【发布时间】:2016-07-27 10:15:13
【问题描述】:
我在 xaml 中以 DataGrid 为目标的样式中定义了一个 RowStyle:
<Style x:Key="DataGridStyle" TargetType="{x:Type DataGrid}">
<!-- Bunch of other setters -->
<Setter Property="RowStyle">
<Setter.Value>
<Style TargetType="{x:Type DataGridRow}">
<Setter Property="Background">
<Setter.Value>
<MultiBinding Converter="{StaticResource DataGridRowBgConverter}">
<Binding Path="IsThis" />
<Binding Path="IsThat" />
</MultiBinding>
</Setter.Value>
</Setter>
</Style>
</Setter.Value>
</Setter>
某些 DataGrid 需要使用图像作为背景的 RowStyle,以便在某个属性为 true 时显示。
我修改了多重绑定以将数据上下文作为第三个值传递,并修改了转换器以检查 DC 以确定是否需要图像。
不过,我不知道如何构建 xaml。
更新:
这似乎工作,除了设置双向绑定,我需要指定一个路径。
<Setter Property="Background">
<Setter.Value>
<ImageBrush Binding="{Binding Converter={StaticResource DataGridRowImageConverter}}" />
</Setter.Value>
</Setter>
如何设置绑定路径以绑定到 DC(相当于<Binding />)?上面 xaml 中的绑定给了我必要的 DC;如何使用 Path 表达相同的内容?
感谢您的任何见解....
【问题讨论】: