如何设置TwoWay多重绑定... [英] How do I set up a TwoWay multibinding...

查看:59
本文介绍了如何设置TwoWay多重绑定...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我设置了这样一个简单的多重绑定:

Hi,
I set up a simple multibinding like this:

<Border removed="#FF880000" BorderThickness="1" BorderBrush="Black" CornerRadius="5" Margin="5"> 
                        <TextBox removed="Transparent" MaxLength="3" Text="{Binding ElementName=SRed, Path=Value, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Foreground="WhiteSmoke" MinWidth="40" Margin="2" BorderBrush="Transparent"/>
                    </Border>
                    <Border removed="#FF008800" BorderThickness="1" BorderBrush="Black" CornerRadius="5" Margin="5">
                        <TextBox removed="Transparent" MaxLength="3" Text="{Binding ElementName=SGreen, Path=Value, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Foreground="WhiteSmoke" MinWidth="40" Margin="2" BorderBrush="Transparent"/>
                    </Border>
                    <Border removed="#FF000088" BorderThickness="1" BorderBrush="Black" CornerRadius="5" Margin="5">
                        <TextBox removed="Transparent" MaxLength="3" Text="{Binding ElementName=SBlue, Path=Value, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Foreground="WhiteSmoke" MinWidth="40" Margin="2" BorderBrush="Transparent"/>
                    </Border>
                    <Border removed="#FF666666" BorderThickness="1" BorderBrush="Black" CornerRadius="5" Margin="5">
                        <TextBox removed="Transparent" MaxLength="3" Text="{Binding ElementName=SA, Path=Value, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Foreground="WhiteSmoke" MinWidth="40" Margin="2" BorderBrush="Transparent"/>
                    </Border>
                    <Border removed="#FF00B9B9" BorderThickness="1" BorderBrush="Black" CornerRadius="5" Margin="5">
                        <TextBox removed="Transparent" Foreground="WhiteSmoke" MinWidth="40" Margin="2" BorderBrush="Transparent">
                            <TextBox.Text>
                                <MultiBinding Converter="{StaticResource RTHC}" Mode="TwoWay">
                                    <Binding ElementName="SRed" Path="Value" />
                                    <Binding ElementName="SGreen" Path="Value" />
                                    <Binding ElementName="SBlue" Path="Value" />
                                    <Binding ElementName="SA" Path="Value" />
                                </MultiBinding>
                            </TextBox.Text>
                        </TextBox>
                    </Border>



这是对其他文本框的双向MultiBinding。

然后我创建了这个类:


Which is a twoWay MultiBinding to the other textboxes.
Then I created this class:

public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            byte R = byte.Parse(values[0].ToString());
            byte G = byte.Parse(values[1].ToString());
            byte B = byte.Parse(values[2].ToString());
            byte A = byte.Parse(values[3].ToString());
            return DecToHex(A) + DecToHex(R) + DecToHex(G) + DecToHex(B);
        }

        public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)
        {
            string v = value.ToString();
            return new object[4] { HexToDec(v.Substring(0, 2)), HexToDec(v.Substring(2, 2)), HexToDec(v.Substring(4, 2)), HexToDec(v.Substring(6, 2)) };
        }





Eberything正确实现,但是当我更改我设置的文本框中的值时,文本框不会更新这是一些截图:

http://snap.ashampoo.com/Yvu9z61n [ ^ ]

http://snap.ashampoo.com/Z6Rmvl6u [ ^ ]

http://snap.ashampoo.com/fVwFrBI8 [ ^ ]



谢谢。



--- Jymmy097



Eberything is implemented correctly, but the textboxes do not get updated when I change the value in the textbox I set the multibinding in.

Here are some screenshots:
http://snap.ashampoo.com/Yvu9z61n[^]
http://snap.ashampoo.com/Z6Rmvl6u[^]
http://snap.ashampoo.com/fVwFrBI8[^]

Thanks.

---Jymmy097

推荐答案





你可以尝试这个代码,





you could try this code,

<TextBox.Text>
 <MultiBinding Converter="{StaticResource RTHC}" Mode="TwoWay", UpdateSourceTrigger=PropertyChanged>
                                    <Binding ElementName="SRed" Path="Value" />
                                    <Binding ElementName="SGreen" Path="Value" />
                                    <Binding ElementName="SBlue" Path="Value" />
                                    <Binding ElementName="SA" Path="Value" />
                                </MultiBinding>
                            </TextBox.Text>





这是因为,Text属性具有PropertyChanged的默认值LostFocus。



问候,

Karuppasamy P



This is because, Text property has a default value of LostFocus for the PropertyChanged.

Regards,
Karuppasamy P


这篇关于如何设置TwoWay多重绑定...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆