[英]MultiBinding Converter not binding to TextBlock in DataTemplate
[英]DataTemplate binding grid background through a converter
我有一阵子的问题是数据绑定更改了网格的颜色,并且以某种方式不起作用。 我在转换器中放置了一个断点,应用程序命中了它,但是网格的背景颜色仍然没有改变,并且由于没有定义背景颜色而保持不变...
这是我的代码:
<ListView ItemsSource="{Binding ResultsUserControls}"
Background="{x:Null}"
BorderBrush="{x:Null}">
<ListView.ItemTemplate>
<DataTemplate>
<Grid Width="200"
Height="70"
Background="{Binding CurrentResult,Converter={StaticResource crawlerTypeToResultColorConverter}}">
<Label Content="{Binding .CurrentResult.SourceUrl}" />
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
和转换器:
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return Brushes.Red;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return Binding.DoNothing;
}
我认为这应该是
public object Convert(object value, Type targetType, object parameter,
System.Globalization.CultureInfo culture)
{
return new SolidColorBrush(Colors.Red);
}
public object ConvertBack(object value, Type targetType, object parameter,
System.Globalization.CultureInfo culture)
{
return Binding.DoNothing;
}
我已经修改了您的代码,您所拥有的应该可以正常工作。 作为实验,请从您的Background绑定中删除CurrentResult:
<Grid Width="200" Height="70" Background="{Binding Converter={StaticResource crawlerTypeToResultColorConverter}}">
我怀疑您现在会看到红色背景。 我注意到,如果XAML解析器找不到您要绑定到的属性(因为它的拼写错误或不存在),它将不会进行转换。 我猜想XAML解析器无法在您的项目上找到CurrentResult。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.