Click here to Skip to main content
15,884,425 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I set up a simple multibinding like this:
XML
<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>

Which is a twoWay MultiBinding to the other textboxes.
Then I created this class:
C#
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 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
Posted
Updated 12-Sep-19 21:29pm
Comments
LLLLGGGG 17-Mar-14 12:26pm    
Anyone?

1 solution

hi,

you could try this code,

XML
<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>


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

Regards,
Karuppasamy P
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900