MVVM WPF 绑定颜色
程序员文章站
2022-03-08 15:57:35
<Button Margin="2" Width="10" >
<Button.Background>
<SolidColorBrush Color="{Binding Path=MarkColor}"></SolidColorBrush>
</Button.Background>
</Button>
这样即可绑定
但是需要注意的是这里的Color是System.Windows.Media.Color不是Drawing.Color
也可以直接Background绑定,但是需要进行一个convert
public class Matrix2Len : IValueConverter
{
object IValueConverter.Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value == null)
return 0;
else
{
List<List<double>> data = (List<List<double>>)value;
return data[0].Count/1000;
}
}
object IValueConverter.ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
本文地址:https://blog.csdn.net/gunjiu4462/article/details/107388362