0
我有一個DataGrid的ItemsSource屬性綁定到我的ViewModel的屬性!wpf綁定在模板和ItemsSource屬性
<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')
我同意呢!綁定到columnheader的對象上沒有名爲ComboDataSource的屬性。
如何將我的組合框綁定到不同的源?
pb解決了,thx! – bricer