Tag: imultivalueconverter

如何将三个滑块的值转换为颜色?

我正在尝试创建一个自定义用户控件,允许用户在WPF中定义颜色。 我之前在WinForms中做过这个,但在WPF中它似乎并不那么直接。 这也是我第一次处理多转换器。 控件有3个滑块 – 就像这样: 唯一的区别是每个的名称 – sdrRed,sdrGreen和sdrBlue。 这是多值转换器: public class ByteToColorConverter : IMultiValueConverter { public object Convert( object[ ] values, Type targetType, object parameter, System.Globalization.CultureInfo culture ) { return Color.FromArgb( (byte)values[0], (byte)values[1], (byte)values[2], (byte)values[3]); } public object[ ] ConvertBack( object value, Type[ ] targetTypes, object parameter, System.Globalization.CultureInfo culture ) { Color C = […]

使用IValueConverter动态加载图像源

我有IValueconverter的问题并动态加载行网格图像: public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { string Type = (string)value; Uri uri; try { uri = new Uri(“/XConsole;component/Images/” + Type + “.png”, UriKind.Relative); return new System.Windows.Media.Imaging.BitmapImage(uri) { CacheOption = BitmapCacheOption.None }; } catch (Exception e) { //donothing } uri = new Uri(“/XConsole;component/Images/Type_SYSTEM.png”, UriKind.Relative); return new System.Windows.Media.Imaging.BitmapImage(uri) { CacheOption = […]