She*_*ock 5 wpf xaml ivalueconverter multibinding
看一下以下XAML代码段:
<DataGridTextColumn.CellStyle>
<Style TargetType="{x:Type DataGridCell}">
<Setter Property="Background" Value="White"/>
<Setter Property="BorderThickness" Value="0"/>
<Setter Property="Block.TextAlignment" Value="Center"/>
<Setter Property="Background">
<Setter.Value>
<SolidColorBrush>
<SolidColorBrush.Color>
<MultiBinding Converter="{StaticResource VAPBrushConverter}">
<Binding RelativeSource="{RelativeSource FindAncestor, AncestorType={x:Type DataGridCell}}"/>
<Binding RelativeSource="{RelativeSource FindAncestor, AncestorType={x:Type UserControl}}"/>
</MultiBinding>
</SolidColorBrush.Color>
</SolidColorBrush>
</Setter.Value>
</Setter>
</Style>
</DataGridTextColumn.CellStyle>
Run Code Online (Sandbox Code Playgroud)
仅在滚动数据网格时才调用IValueConverter 。在DataGridCell中,有一个TextBlock,并且只有在TextBlock.Text属性为DependencyProperty.UnsetValue时,才调用IValueConverter。
有人可以告诉我何时调用IValueConverter,并且当前是否可以使用我的代码来解决此问题?澄清一下-问题是,当我在DataGrid上滚动时,背景仅由IValueConverter设置。
我通过将绑定设置为项目源中的当前元素解决了这个问题,如下所示:
<Binding Path="."/>
<Binding RelativeSource="{RelativeSource FindAncestor, AncestorType={x:Type UserControl}}"/>
Run Code Online (Sandbox Code Playgroud)
看起来问题在于 IValueConverter 仅在调用 get/set 访问器时才被调用。我在绑定中传递 DataGridCell,该绑定仅在滚动时获取/设置。每当值更改时,都会获取/设置单元格的内容,因此这意味着 IValueConverter 将相应更新。
| 归档时间: |
|
| 查看次数: |
327 次 |
| 最近记录: |