我正在使用MVVM模式,我有一个DataGrid,其列显示一些图片,如果两个布尔值设置为true。一个值在DataView(DtView)中,它绑定生成行,绑定没有问题,但另一个值是ViewModel的公共属性(与DtView相同),这里有问题。我不知道如何解决这个问题 这是我的代码:
<DataGrid ItemsSource="{Binding Path=DtView}">
<DataGrid.Columns>
<DataGridTemplateColumn Header="Status">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Image Source="../Images/a.png" Width="18" Height="18">
<Image.Style>
<Style TargetType="Image">
<Setter Property="Visibility" Value="Collapsed" />
<Style.Triggers>
<MultiDataTrigger>
<MultiDataTrigger.Conditions>
<Condition Binding="{Binding 'column from DtView'}" Value="True" />
<Condition Binding="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=Column from other DataView}" Value="True" />
</MultiDataTrigger.Conditions>
<Setter Property="Visibility" Value="Visible" />
</MultiDataTrigger>
</Style.Triggers>
</Style>
</Image.Style>
</Image>
</StackPanel>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>
如果有人可以帮助我,我会非常高兴,因为这令人沮丧,我不知道如何修复此代码。
答案 0 :(得分:1)
尝试
<MultiDataTrigger.Conditions>
<Condition Binding="{Binding 'column from DtView'}" Value="True" />
<Condition Binding="{Binding RelativeSource={RelativeSource AncestorType={x:Type DataGrid}},
Path=DataContext.OtherDtView.Column from other DataView}" Value="True" />
</MultiDataTrigger.Conditions>