Posts

Showing posts with the label Xaml

Collapse Grid Row In WPF

Answer : All you need is something to cache the height(s) of the visible row. After that, you no longer need converters or to toggle visibility of contained controls. CollapsibleRow public class CollapsibleRow : RowDefinition { #region Fields private GridLength cachedHeight; private double cachedMinHeight; #endregion #region Dependency Properties public static readonly DependencyProperty CollapsedProperty = DependencyProperty.Register("Collapsed", typeof(bool), typeof(CollapsibleRow), new PropertyMetadata(false, OnCollapsedChanged)); private static void OnCollapsedChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { if(d is CollapsibleRow row && e.NewValue is bool collapsed) { if(collapsed) { if(row.MinHeight != 0) { row.cachedMinHeight = row.MinHeight; row.MinHeight = 0; } ...

Aligning Content In A WPF Viewbox

Answer : Try VerticalAlignment="Top" and HorizontalAlignment="Left" on your viewbox. It will cause it to be anchored to the top and left side. <Grid> <Viewbox VerticalAlignment="Top" HorizontalAlignment="Left"> ... </Viewbox> </Grid> If you want it to completely fill (but keep it uniform) you can use Stretch="UniformToFill"

Change Margin Programmatically In WPF / C#

Answer : test.Margin = new Thickness(0, -5, 0, 0); Alignment, Margins and Padding Overview (MSDN) FrameworkElement.Margin (MSDN) test.Margin = new Thickness(0, 0, 0, 0); test.Margin = new Thickness(-5);

Add A PDF Viewer To A WPF Application

Answer : As already suggested by @NawedNabiZada, one tried and straightforward way is to use embedded InternetExplorer to show Adobe PDF Reader ActiveX control. So it assumes you are running on Windows and have Adobe PDF Reader installed. Then you create a user control, window etc. that contains following control: <WebBrowser x:Name="pdfWebViewer"></WebBrowser> In the constructor navigate to blank page: pdfWebViewer.Navigate(new Uri("about:blank")); To load a PDF document to that control use this simple code: pdfWebViewer.Navigate(fullPathToPDF); This approach is used by many Windows software not only WPF apps including SAP client, but has a hidden problem, see this question. The Adobe PDF Reader Addon in Internet Explorer must be enabled for this to work. There are various problems with Acrobat Reader XI, better to use DC version. To enable Adobe PDF go to IE settings, add-ons and find Adobe PDF Reader and enable it (AR XI and above...