简体   繁体   English

从值转换器将颜色值分配给 BackgroundColor 属性

[英]Assigning Color Value to BackgroundColor Property from Value Converter

Using a converter (IValueConverter) to change background color aa border, but it does not assign the color value correctly to the BackgroundColor property.使用转换器 (IValueConverter) 将背景颜色更改为边框,但它没有将颜色值正确分配给 BackgroundColor 属性。

Converter is straight forward: numeric value from source, conversion from an int (0-5) to a color name (string such as Orange, Pink, etc.).转换器很简单:来自源的数值,从 int (0-5) 转换为颜色名称(字符串,如橙色、粉红色等)。

Screenshot demonstrates the issue:屏幕截图演示了该问题: 在此处输入图像描述

Figured it out on my own.我自己想出来的。

For reference, I changed the assignment of the output of the value converter from BackgroundColor to simply Background.作为参考,我将值转换器的 output 的分配从 BackgroundColor 更改为简单的 Background。 Also, I changed the output from the value converter from a string (eg Red, White, etc) to a new brush (eg return new SolidColorBrush(Colors.Orange)).此外,我将 output 从值转换器从字符串(例如红色、白色等)更改为新画笔(例如返回新的 SolidColorBrush(Colors.Orange))。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM