Posts

Showing posts with the label Wpf

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"

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...

Bottom Borders On WPF Grid

Answer : On a Border control You can do BorderThickness="0 0 0 1" to only have a bottom border shown. Top and bottom border thickness of 5, left and right border thickness of 0 BorderThickness="0 5" Top and bottom border thickness of 0, left and right border thickness of 5 BorderThickness="5 0" Border Thickness - Left: 1, Top: 2, Right:3, Bottom: 4 BorderThickness="1 2 3 4" Hope this helps!

ConfigurationManager In WPF

Answer : Just add an app.config and not web.config because it is not a web application. And after that it's too simple, just add a reference to to System.Configuration and then use this. var ConnStr = ConfigurationManager.AppSettings["Trackboard"]; I've figured it out! I shouldn't have created a new config file. There is a default app.config file in the project. Now everything is fine. <?xml version="1.0" encoding="utf-8" ?> <configuration> <configSections> </configSections> <connectionStrings> <add name="Trackboard.Properties.Settings.TrackboardConnectionString" connectionString="Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\DATABASE\Trackboard.mdf;Integrated Security=True" providerName="System.Data.SqlClient" /> </connectionStrings> </configuration> private static string ConnStr = ConfigurationMana...

Align DataGrid Column Header To Center

Answer : Check this <DataGridTextColumn Header="Nombre" Binding="{Binding Nombre}"> <DataGridTextColumn.HeaderStyle> <Style TargetType="DataGridColumnHeader"> <Setter Property="HorizontalContentAlignment" Value="Center" /> </Style> </DataGridTextColumn.HeaderStyle> It should be StaticResource instead of DynamicResource in the Column: Style <Window.Resources> <Style x:Key="CenterGridHeaderStyle" TargetType="DataGridColumnHeader"> <Setter Property="HorizontalContentAlignment" Value="Center"/> </Style> </Window.Resources> Column <DataGridTextColumn Binding="{Binding Path=Name}" Header="Name" IsReadOnly="True" HeaderStyle="{StaticResource CenterGridHeaderStyle}"/> There is a response for doing it progr...

C# WPF - ScrollViewer + TextBlock Troubles

Answer : This works: <Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> <ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto" Name="Scroller"> <TextBlock HorizontalAlignment="Stretch" VerticalAlignment="Stretch" MinWidth="100" Width="{Binding ElementName=Scroller, Path=ViewportWidth}" TextWrapping="Wrap" Text="Some really long text that should probably wordwrap when you resize the window." /> </ScrollViewer> </Window> Without more detail, the best I can do is provide the standard way of doing this. Basically, host your element (which has a minimum size) in a scroll viewer; when th...

Building A Great Dashboard App In WPF -- What Are The Controls Available Out There?

Answer : Check out the WPF Dashboard demo. It comes with source code. Also the WPF Dashboard project on codeplex. The Infragistics Dashboard demo is nice as well. My decision was to take the DragDockPanel from the Blacklight project. It's both WPF and Silverlight-enabled.