我在数据网格模板中有一个组合框。 我有一个事件触发器,它调用一个命令。我已确认该命令正在调用我的功能。 当我的函数返回false时,我想将组合框的背景颜色设置为黄色。如果返回true,我希望它保持白色。WPF datagrid模板列组合框绑定表达式错误
的问题似乎是在以下部分:
"Path=DataContext.ApplicationProfilesCollection[].ValidEnvironment"
在输出窗口,我得到:
"System.Windows.Data Error: 40 : BindingExpression path error: '[]' property not found on 'object' ''ObservableCollection`1' (HashCode=44314665)'. BindingExpression:Path=DataContext.ApplicationProfilesCollection[].ValidEnvironment; DataItem='ProfilesUserControl' (Name=''); target element is 'ComboBox' (Name=''); target property is 'NoTarget' (type 'Object')"
目前有集合中的3项。你知道我如何让粮食计划署认识到每一个? XAML中的“[]”是否有任何内容? 另外 - 我必须坚持MVVM模式。
请参阅下面的XAML。 感谢您的时间,
<DataTemplate DataType="models:ApplicationProfile">
<ComboBox ItemsSource="{Binding RelativeSource={RelativeSource
Mode=FindAncestor,
AncestorType={x:Type UserControl}},
Path=DataContext.DsnCollection}"
Validation.ErrorTemplate="{StaticResource ValidationTemplate}"
SelectedItem="{Binding DataSource, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True}">
<i:Interaction.Triggers>
<i:EventTrigger EventName="SelectionChanged">
<i:InvokeCommandAction Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}, Path=DataContext.ValidateDataSourceCommand}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
<ComboBox.Style>
<Style TargetType="ComboBox">
<Style.Triggers>
<DataTrigger Binding="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}, Path=DataContext.ApplicationProfilesCollection[].ValidEnvironment}" Value="false">
<Setter Property="ComboBox.Background" Value="Yellow"/>
</DataTrigger>
</Style.Triggers>
</Style>
</ComboBox.Style>
</ComboBox>
ComboBox中的项目(即DsnCollection中的项目)是否具有ValidEnvironment属性?或者这个属性在哪里定义? – mm8
你需要显示你的数据模型,因为异常消息显示def你的数据绑定是错误的 – esiprogrammer
显然'[]'不是用XAML写的有效的东西。你能澄清你想要做什么吗?我相信你需要使用一个转换器,但我不确定你想要做什么。 – Kilazur