我将 DataGrid 的 ItemsSource 属性绑定到我的 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" />
如您所见,DataGrid 有一个特殊的标题模板。
<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>
问题:组合框未填充。
我有这个输出:
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')
我同意!绑定到列标题的对象上没有名为 ComboDataSource 的属性。
如何将我的组合框绑定到不同的源?