当前位置:网站首页>【WPF】转换器Converter
【WPF】转换器Converter
2022-04-21 06:34:00 【阿月浑子2021】
作用:完成源值和绑定目标的值之间的转换
Convert:将原值转换为绑定目标的值。数据绑定引擎在将该值从源绑定传播到绑定目标时会调用到此方法
ConvertBack:将绑定目标值转换为源绑定值
值转换器:实现 IValueConverter 接口
<Window.Resources>
<local:Converter x:Key="convert"/>
</Window.Resources>
<StackPanel Orientation="Vertical">
<TextBlock Text="0" x:Name="_text1" FontSize="50"/>
<TextBlock Text="{Binding Path=Text,ElementName=_text1,Converter={StaticResource convert}}" FontSize="50"/>
<TextBlock Text="1" x:Name="_text2" FontSize="50"/>
<TextBlock Text="{Binding Path=Text,ElementName=_text2,Converter={StaticResource convert}}" FontSize="50"/>
</StackPanel>
public class Converter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value == null) return null;
return value.ToString() == "0" ? "Yes" : "No";
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}

多值转换器:实现IMultiValueConverter
<Window.Resources>
<local:Converter x:Key="convert"/>
</Window.Resources>
<StackPanel Orientation="Vertical">
<Slider x:Name="_sliderR" Minimum="0" Maximum="255" Width="200" Height="30" Margin="10"/>
<Slider x:Name="_sliderG" Minimum="0" Maximum="255" Width="200" Height="30" Margin="10"/>
<Slider x:Name="_sliderB" Minimum="0" Maximum="255" Width="200" Height="30" Margin="10"/>
<Path HorizontalAlignment="Center">
<Path.Data>
<EllipseGeometry RadiusX="50" RadiusY="50" Center="100,100"/>
</Path.Data>
<Path.Fill>
<MultiBinding Converter="{StaticResource convert}">
<Binding ElementName="_sliderR" Path="Value"/>
<Binding ElementName="_sliderG" Path="Value"/>
<Binding ElementName="_sliderB" Path="Value"/>
</MultiBinding>
</Path.Fill>
</Path>
</StackPanel>
public class Converter : IMultiValueConverter
{
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
if (values == null || values.Length < 3) return null;
return new SolidColorBrush(Color.FromRgb(System.Convert.ToByte(values[0]), System.Convert.ToByte(values[1]), System.Convert.ToByte(values[2])));
}
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}


版权声明
本文为[阿月浑子2021]所创,转载请带上原文链接,感谢
https://blog.csdn.net/weixin_56814032/article/details/122088728
边栏推荐
- BGP 自动路由聚合
- 【计组】性能
- 2020-12-24
- NP、OSPF链路状态数据库
- 国产POE,RPC304,替换IP802、IP804、IP808,替换TPS23861、LTC4292、PD69204、SI3459,国产首发POE供电、PSE,睿普康国产以太网供电及接口转换芯片
- 龙讯系列:LT8912B,LT6911C,HDMI转MIPI(CSI\DSI),单通道MIPI2.DSI桥到LVDS/HDM,HDMI1.4到双端口MIPIDSI/CSI与音频数据表
- BGP 认证功能
- Sort method ----- > Hill sort, heap sort
- NP, OSPF Stub Area
- Sorting method (1) = > bubble sorting, simple selection sorting
猜你喜欢

BGP 邻居

NP、OSPF Stub区域

China Resources micro power amplifier cs3850eo, 2 × 40W class D audio power amplifier circuit, replacement: Zhipu core cs8673, tas5780 and tas5754 of Ti, domestic power amplifier

Cs5801 specification | cs5801 HDMI to EDP conversion scheme | HDMI to DP adapter board design, hdmi2 0 turn edp1 4. Support downward compatibility

Weak password-20211221

Jfinal hutool tool excel util ziputil realizes exporting excel and compressing files

迷你考试系统v1.0.0版本

Longxun series: lt8912b, lt6911c, HDMI to Mipi (CSI \ DSI), single channel mipi2 DSi bridge to LVDS / HDM, hdmi1 4 to dual port mipidsi/csi and audio data sheet

【WPF】自定义Combobox

三层交换机与路由器对接上网
随机推荐
Echars control legend all or none - simple case
2020-12-24
蓝桥杯——十六进制转八进制
BGP 邻居
CS5518,MIPI转双路LVDS,替换:国腾的GM8775,东芝TC358775,双路LVDS,国产完美替换,DSI 转双通道 LVDS,,LVDS 时钟频率最高154MHz,1920 x1200
国产POE,RPC304,替换IP802、IP804、IP808,替换TPS23861、LTC4292、PD69204、SI3459,国产首发POE供电、PSE,睿普康国产以太网供电及接口转换芯片
MS1836S,HDMI转CVBS,视频转换器,HDMI接收器,内置 MCU 和存储器
宏晶微MS9123,USB 投屏控制芯片,USB 投屏器,支持 CVBS、S-Video 视频接口,
Cs5518, Mipi to dual LVDS, replacement: gm8775 of Guoteng, tc358775 of Toshiba, dual LVDS, domestic perfect replacement, DSI to dual channel LVDS, LVDS clock frequency up to 154mhz, 1920 x1200
【无标题】国腾GM系列,GM8284DD(GM8284DR,LT8218A)、 GM8285C、GM7123C,LVDSTTL转TTL,TTL转成单路LVDS,TTL数字信号转换成VGA
Optimal solution of steel bar cutting problem
集创北方,Chipone,ICN6211,ICN6202,MIPI转RGB,MIPI转LVDS,分辨率最高1080P,MIPI DSI转换,mipi转换,
NP, OSPF stub area
NP, OSPF route aggregation
Nmap scanning and scapy projects
About IMAP tools module to achieve mail movement
蕊源:RY3408、RY3410主要替换:矽力杰SY8088、SY8089,TI的TLV62568、TLV62565芯源的MP2161、MP2128、MP2105
Solve the problem of Chinese garbled code
NP、OSPF Stub區域
2020-12-24