4
滾動時纔會被調用看看下面的XAML代碼片段:的IValueConverter上的DataGrid
<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>
的的IValueConverter被稱爲只有當我滾動DataGrid中。在DataGridCell內部有一個TextBlock,而另一次調用IValueConverter時,TextBlock.Text屬性爲DependencyProperty.UnsetValue。
有人能告訴我什麼時候IValueConverter被調用,如果有什麼我可以用我的代碼目前可以解決這個問題?澄清 - 問題是,當我在DataGrid上滾動時,僅由IValueConverter設置背景。
我有同樣的問題。 –
您使用MultiBindings和Converters過度複雜。爲你的行創建一個合適的ViewModel,並有一些「更容易」的值綁定或使用'DataTriggers'。 –
@HighCore我明白你在說什麼,但我的ViewModel正在被轉換爲JSON直接在另一個API中使用,所以我不能真正爲我的前端應用程序添加隨機屬性。我可以創建一些裝飾器,但我寧願使用轉換器來保持一致性。 – Sherlock