wpf 一个dateContent 的容器用的一个控件样式显示到前台上,怎么样动态改变它的颜色,现在的颜色是写死的
展开全部
public class PriceToBackgroundConverter : IValueConverter //绑定到需要画刷改变的位置:如列表项的Template中的item的包含控件如Border.使用画刷不用颜色这样就可以使用更多效果,而且代码没有硬编码画刷,使用属性来获取
{
public decimal MinimumPriceToHighlight{get;set;}
public Brush HighlightBrush{get;set;}
public Brush DefaultBrush{get;set;}
public object Convert(object value, Type
targetType, object parameter,
System.Globalization.CultureInfo culture)
{
decimal
price = (decimal)value;
if (price
>= MinimumPriceToHighlight)
return
HighlightBrush;
else
return
DefaultBrush;
}
public object ConvertBack(object value, Type
targetType, object parameter,
System.Globalization.CultureInfo culture)
{
throw new NotSupportedException();
}
}
XAML
<local:PriceToBackgroundConverter x:Key="PriceToBackgroundConverter"
DefaultBrush="{x:Null}"
HighlightBrush="Orange" MinimumPriceToHighlight="10">
</local:PriceToBackgroundConverter>
Background="{Binding Path=UnitCost, Converter={StaticResource PriceToBackgroundConverter}}"
{
public decimal MinimumPriceToHighlight{get;set;}
public Brush HighlightBrush{get;set;}
public Brush DefaultBrush{get;set;}
public object Convert(object value, Type
targetType, object parameter,
System.Globalization.CultureInfo culture)
{
decimal
price = (decimal)value;
if (price
>= MinimumPriceToHighlight)
return
HighlightBrush;
else
return
DefaultBrush;
}
public object ConvertBack(object value, Type
targetType, object parameter,
System.Globalization.CultureInfo culture)
{
throw new NotSupportedException();
}
}
XAML
<local:PriceToBackgroundConverter x:Key="PriceToBackgroundConverter"
DefaultBrush="{x:Null}"
HighlightBrush="Orange" MinimumPriceToHighlight="10">
</local:PriceToBackgroundConverter>
Background="{Binding Path=UnitCost, Converter={StaticResource PriceToBackgroundConverter}}"
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询