I have the ItemsSource property of a DataGrid bind to a property of my ViewModel!
<DataGrid ItemsSource="{Binding Path=ExcelData}" ColumnHeaderStyle="{DynamicResource ColumnHeaderStyle}" Grid.Row="1" Margin="0 10 0 10" Visibility="{Binding DisplayGridView, Converter={StaticResource booltovisibility}}" CanUserReorderColumns="False" CanUserResizeColumns="False" CanUserSortColumns="False" />
As you can see, the DataGrid has a special header template.
<Style x:Key="ColumnHeaderStyle" TargetType="{x:Type DataGridColumnHeader}">
<Setter Property="VerticalContentAlignment" Value="Center" />
<Setter Property="Background" Value="{x:Static pm:MetroColors.FeatureBrush}" />
<Setter Property="Foreground" Value="White" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="DataGridColumnHeader">
<Border BorderThickness="2" CornerRadius="5" Background="{x:Static pm:MetroColors.FeatureBrush}" BorderBrush="{x:Static pm:MetroColors.FeatureBrush}">
<StackPanel>
<ComboBox ItemsSource="{Binding ComboDataSource}" DisplayMemberPath="Text" SelectedValuePath="Name" ext:ComboBoxExtensions.ComboBoxName="{TemplateBinding Content}" SelectionChanged="ComboBox_SelectionChanged" />
<Label Content="{TemplateBinding Content}" />
</StackPanel>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
Problem : the combobox is not filled.
I have this output :
System.Windows.Data Error: 40 : BindingExpression path error: 'ComboDataSource' property not found on 'object' ''String' (HashCode=752763509)'. BindingExpression:Path=ComboDataSource; DataItem='String' (HashCode=752763509); target element is 'ComboBox' (Name=''); target property is 'ItemsSource' (type 'IEnumerable')
I am agree with it! there is no property named ComboDataSource on the object binded to the columnheader.
How can I bind my combobox to a different source?