FindVisualChild reference issue

FindVisualChild method is not provided by WPF framework, you have to add them. May be you want this: public static IEnumerable<T> FindVisualChildren<T>(DependencyObject depObj) where T : DependencyObject { if (depObj != null) { for (int i = 0; i < VisualTreeHelper.GetChildrenCount(depObj); i++) { DependencyObject child = VisualTreeHelper.GetChild(depObj, i); if (child != null && child is … Read more

WPF DataGrid: DataGridComboxBox ItemsSource Binding to a Collection of Collections

Firstly, this should be easy… secondly, why are you building (and binding) columns in C#? Eek. XAML (I’m using a regular grid because I’m lazy): <ListView Name=”MyListView”> <ListView.View> <GridView> <GridView.Columns> <GridViewColumn DisplayMemberBinding=”{Binding Operation}” /> <GridViewColumn> <GridViewColumn.CellTemplate> <DataTemplate> <ComboBox ItemsSource=”{Binding Choices}” /> </DataTemplate> </GridViewColumn.CellTemplate> </GridViewColumn> </GridView.Columns> </GridView> </ListView.View> </ListView> C#: void Window1_Loaded(object sender, RoutedEventArgs e) { … Read more

Binding in a WPF data grid text column

Jared’s answer is correct, but I’ve found a concrete solution that’s solved my problem. http://blogs.msdn.com/vinsibal/archive/2008/12/17/wpf-datagrid-dynamically-updating-datagridcomboboxcolumn.aspx Following this example, I changed my DataGridTextColumn definition to: <dg:DataGridTextColumn Binding=”{Binding Font.Name}” IsReadOnly=”True” Header=”Font”> <dg:DataGridTextColumn.ElementStyle> <Style TargetType=”TextBlock”> <Setter Property=”FontFamily” Value=”{Binding Font.Name}” /> </Style> </dg:DataGridTextColumn.ElementStyle> </dg:DataGridTextColumn> And I don’t need to worry about the column inheriting the DataContext. This gives me … Read more

Binding a WPF DataGridComboBoxColumn with MVVM

Here is a working code. The key point here was to use SelectedValueBinding instead of SelecteItemBinding. <DataGridComboBoxColumn Header=”Title” SelectedValueBinding=”{Binding TitleId}” SelectedValuePath=”TitleId” DisplayMemberPath=”TitleText” > <DataGridComboBoxColumn.ElementStyle> <Style TargetType=”ComboBox”> <Setter Property=”ItemsSource” Value=”{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=DataContext.Titles}”/> </Style> </DataGridComboBoxColumn.ElementStyle> <DataGridComboBoxColumn.EditingElementStyle> <Style TargetType=”ComboBox”> <Setter Property=”ItemsSource” Value=”{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=DataContext.Titles}”/> </Style> </DataGridComboBoxColumn.EditingElementStyle> </DataGridComboBoxColumn>

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

Merge Cells in WPF DataGrid

Try use DataGridTemplateColumn. I created sample test class for databinding public class Test { public Test(string name, string attribute1, string attribute2) { Name = name; Attributes = new Attribute(attribute1, attribute2); } public string Name { get; set; } public Attribute Attributes { get; set; } } public class Attribute { public Attribute(string attribute1, string attribute2) … Read more

Date formatting in WPF datagrid

Don`t forget to use DataGrid.Columns, all columns must be inside that collection. In my project I format date a little bit differently: <tk:DataGrid> <tk:DataGrid.Columns> <tk:DataGridTextColumn Binding=”{Binding StartDate, StringFormat=\{0:dd.MM.yy HH:mm:ss\}}” /> </tk:DataGrid.Columns> </tk:DataGrid> With AutoGenerateColumns you won`t be able to contol formatting as DataGird will add its own columns.