DataGrid row content vertical alignment

Complete solution of this issue at MSDN: Vertical alignment of DataGrid row content. In brief, in style-file set: <!–body content datagrid cell vertical centering–> <Style x:Key=”Body_Content_DataGrid_Centering” TargetType=”{x:Type DataGridCell}”> <Setter Property=”Template”> <Setter.Value> <ControlTemplate TargetType=”{x:Type DataGridCell}”> <Grid Background=”{TemplateBinding Background}”> <ContentPresenter VerticalAlignment=”Center” /> </Grid> </ControlTemplate> </Setter.Value> </Setter> </Style> In window file: <DataGrid x:Name=”ContentDataGrid” Style=”{StaticResource ContentDataGrid}” CellStyle=”{StaticResource Body_Content_DataGrid_Centering}” ItemsSource=”{Binding}” … Read more

How can I define a variable in XAML?

Try this: add to the head of the xamlfile xmlns:System=”clr-namespace:System;assembly=mscorlib” Then Add this to the resource section: <System:Double x:Key=”theMargin”>2.35</System:Double> Lastly, use a thickness on the margin: <Button Content=”Next”> <Button.Margin> <Thickness Top=”{StaticResource theMargin}” Left=”0″ Right=”0″ Bottom =”{StaticResource theMargin}” /> </Button.Margin> </Button> A lot of system types can be defined this way: int, char, string, DateTime, etc … Read more

Bind Collection to StackPanel

Alright I have figured it out… Using an ItemsControl solved the problem… <ItemsControl x:Name=”tStack” ItemsSource=”{Binding Items}”> <ItemsControl.ItemsPanel> <ItemsPanelTemplate> <StackPanel Orientation=”Horizontal”/> </ItemsPanelTemplate> </ItemsControl.ItemsPanel> <ItemsControl.ItemTemplate> <DataTemplate> <Button Content=”{Binding ItemName}”/> </DataTemplate> </ItemsControl.ItemTemplate> </ItemsControl>

WPF Binding StringFormat Short Date String

Try this: <TextBlock Text=”{Binding PropertyPath, StringFormat=d}” /> which is culture sensitive and requires .NET 3.5 SP1 or above. NOTE: This is case sensitive. “d” is the short date format specifier while “D” is the long date format specifier. There’s a full list of string format on the MSDN page on Standard Date and Time Format … Read more

How to build A WPF Datagrid with an unknown number of columns

There is DataTable class in .Net. Its primary purpose is to communicate with relational database but it can be used nicely to store, display and edit tabular data (e.g. read and display .csv/Excel files -> DataTable + DataGrid in wpf, DataTable + DataGridView in WinForms). DataTable columns (DataColumn) can be added/removed at runtime and DataGrid … Read more

Pull to refresh On Windows Phone

Check out this: WP8PullToRefreshDetector.cs using Microsoft.Phone.Controls; using System; using System.Windows.Controls.Primitives; /// <summary> /// This class detects the pull gesture on a LongListSelector. How does it work? /// /// This class listens to the change of manipulation state of the LLS, to the MouseMove event /// (in WP, this event is triggered when the user moves … Read more

Where can I download Microsoft’s standard WPF themes from? [closed]

The download links are identical between .NET 3.0 and .NET 3.5–only the online documentation is different. Themes for .NET 3.0 Classic (download) Luna (download) Royale (download) Aero (download) Themes for .NET 3.5 Classic (download) Luna (download) Royale (download) Aero (download) WPF Documentation Samples for .NET 4 and .NET 4.5 Themes (download) (No longer available) Classic … Read more

How to programmatically set selected Panorama item in WP7

I’m not sure if you can programmatically force an animation to another PanoramaItem, but you can change the Panorama.DefaultItem. So you might have 3 PanoramaItem‘s and on the OnNavigatedTo() handler, change the default item via: panoramaControl.DefaultItem = panoramaControl.Items[indexToSet]; This should help when you recover from a tombstone.

Implement INotifyPropertyChanged on generated Entity Framework classes

If you follow the recommended MVVM pattern for WPF, you can treat your generated classes as the Model, and then write ViewModel wrappers that implement INotifyPropertyChanged. The ViewModel classes would access your DB classes and expose properties that you can bind to your UI in XAML. As noted in your comment, this can result in … Read more

tech