locked
DataBinding () - 6/13/2006 10:24 AM PST RRS feed

  • Question

  • By: Bela Istok

    How I can databind 3 slider's to represent an collor in other control, below 
    are my code.
    
    
    -- 
    Bela Istok
    
    <Grid 
    	xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    	xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    	xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    	xmlns:d="http://schemas.microsoft.com/expression/interactivedesigner/2006"
    	Background="#FFFFFFFF" 
    	x:Name="DocumentRoot"
    	Width="480" Height="480">
    	<Grid.Resources>
    	</Grid.Resources>
    
    	<Grid.Triggers>
    	</Grid.Triggers>
    	
    	<Grid.ColumnDefinitions>
    		<ColumnDefinition/>
    	</Grid.ColumnDefinitions>
    	<Grid.RowDefinitions>
    		<RowDefinition/>
    	</Grid.RowDefinitions>
    <DockPanel>
    
    
            <DockPanel Width="33.3">
                <TextBlock DockPanel.Dock="Top" Foreground="Red">Red</TextBlock>
                <TextBlock DockPanel.Dock="Bottom" Foreground="Red" 
    Text="{Binding Value, ElementName=redS, Mode=Default}" />
                <Slider x:Name="redS" Orientation="Vertical" Maximum="255" 
    SmallChange="1" />
            </DockPanel>
    
            <DockPanel Width="33.3">
                <TextBlock DockPanel.Dock="Top" 
    Foreground="Green">Green</TextBlock>
                <TextBlock DockPanel.Dock="Bottom" Foreground="Green" 
    Text="{Binding Value, ElementName=greenS, Mode=Default}" />
                <Slider x:Name="greenS" Orientation="Vertical" Maximum="255" 
    SmallChange="1" />
            </DockPanel>
    
            <DockPanel Width="33.3">
                <TextBlock DockPanel.Dock="Top" Foreground="Blue">Blue</TextBlock>
                <TextBlock DockPanel.Dock="Bottom" Foreground="Blue" Text 
    ="{Binding Value, ElementName=blueS, Mode=Default}"/>
                <Slider x:Name="blueS" Orientation="Vertical" Maximum="255" 
    SmallChange="1" />
            </DockPanel>
    
    
        <TextBlock DockPanel.Dock="Left" 
                   Width="353.05" Background="#FF000000"/>
    </DockPanel>
    </Grid>
    Tuesday, February 19, 2008 12:58 AM

Answers

  • By: George Georgiev

    Hi Bela,

    I can't do it without code, but if you are interested how to do it with a
    minimum code, here is what I propose. Put this code in your code behind
    file:

    private void OnSliderValueChanged(object sender,
    System.Windows.RoutedPropertyChangedEventArgs<double> e)
    {
    myColoredFriend.Background = new
    SolidColorBrush(Color.FromRgb((byte)redS.Value, (byte)greenS.Value,
    (byte)blueS.Value));
    }

    I named your target textbox, myColoredFriend. The only thing you have to do
    is set the ValueChanged event of blueS, greenS and redS to call the
    OnSliderValueChanged method. It is always better to have a custom control,
    but I think this is easier to understand.

    The problem is you can't bind properties of different types unless you have
    a convertor. I would really like to see some common convertors built-in, so
    we can do more without compiled code.

    -- george --

    "Bela Istok" <bela_i@hotmail.com> wrote in message
    news:028E13F2-ECE6-404B-81A4-AAB594B26CF9@microsoft.com...
    > Would be nice that one can do this without code, only seting properties in
    > the XAML code.
    >
    > --
    > Bela Istok
    >
    >
    > "Unni Ravindranathan (MS)" wrote:
    >
    >> Hi Bela,
    >>
    >> The WPF SDK walks you thru this exact scenario in a detailed fashion that
    >> you will find very informative:
    >>
    >>
    http://windowssdk.msdn.microsoft.com/library/en-us/wpf_conceptual/html/ecb97ed4-e659-48a4-a1e0-893309569f2f.asp
    >>
    >> Please note that this sample is quite complicated in the sense that they
    >> are
    >> showing you how to create a color configuration UI in an extensible
    >> fashion.
    >> You can create a simpler version of the same, using the ideas presented
    >> in
    >> this article.
    >>
    >> Thanks,
    >> -Unni
    >> --
    >> This posting is provided "AS IS" with no warranties, and confers no
    >> rights.
    >> "Bela Istok" <bela_i@hotmail.com> wrote in message
    >> news:C91CBACB-AF06-442C-97A3-3A905D252E47@microsoft.com...
    >> > How I can databind 3 slider's to represent an collor in other control,
    >> > below
    >> > are my code.
    >> >
    >> >
    >> > --
    >> > Bela Istok
    >> >
    >> > <Grid
    >> > xmlns="
    http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    >> > xmlns:x="
    http://schemas.microsoft.com/winfx/2006/xaml"
    >> > xmlns:mc="
    http://schemas.openxmlformats.org/markup-compatibility/2006"
    >> > xmlns:d="
    http://schemas.microsoft.com/expression/interactivedesigner/2006"
    >> > Background="#FFFFFFFF"
    >> > x:Name="DocumentRoot"
    >> > Width="480" Height="480">
    >> > <Grid.Resources>
    >> > </Grid.Resources>
    >> >
    >> > <Grid.Triggers>
    >> > </Grid.Triggers>
    >> >
    >> > <Grid.ColumnDefinitions>
    >> > <ColumnDefinition/>
    >> > </Grid.ColumnDefinitions>
    >> > <Grid.RowDefinitions>
    >> > <RowDefinition/>
    >> > </Grid.RowDefinitions>
    >> > <DockPanel>
    >> >
    >> >
    >> > <DockPanel Width="33.3">
    >> > <TextBlock DockPanel.Dock="Top"
    >> > Foreground="Red">Red</TextBlock>
    >> > <TextBlock DockPanel.Dock="Bottom" Foreground="Red"
    >> > Text="{Binding Value, ElementName=redS, Mode=Default}" />
    >> > <Slider x:Name="redS" Orientation="Vertical" Maximum="255"
    >> > SmallChange="1" />
    >> > </DockPanel>
    >> >
    >> > <DockPanel Width="33.3">
    >> > <TextBlock DockPanel.Dock="Top"
    >> > Foreground="Green">Green</TextBlock>
    >> > <TextBlock DockPanel.Dock="Bottom" Foreground="Green"
    >> > Text="{Binding Value, ElementName=greenS, Mode=Default}" />
    >> > <Slider x:Name="greenS" Orientation="Vertical" Maximum="255"
    >> > SmallChange="1" />
    >> > </DockPanel>
    >> >
    >> > <DockPanel Width="33.3">
    >> > <TextBlock DockPanel.Dock="Top"
    >> > Foreground="Blue">Blue</TextBlock>
    >> > <TextBlock DockPanel.Dock="Bottom" Foreground="Blue" Text
    >> > ="{Binding Value, ElementName=blueS, Mode=Default}"/>
    >> > <Slider x:Name="blueS" Orientation="Vertical" Maximum="255"
    >> > SmallChange="1" />
    >> > </DockPanel>
    >> >
    >> >
    >> > <TextBlock DockPanel.Dock="Left"
    >> > Width="353.05" Background="#FF000000"/>
    >> > </DockPanel>
    >> > </Grid>
    >>
    >>
    >>

    Tuesday, February 19, 2008 6:01 PM

All replies

  • By: Unni Ravindranathan (MS)

    Hi Bela,
    
    The WPF SDK walks you thru this exact scenario in a detailed fashion that 
    you will find very informative:
    
    http://windowssdk.msdn.microsoft.com/library/en-us/wpf_conceptual/html/ecb97ed4-e659-48a4-a1e0-893309569f2f.asp
    
    Please note that this sample is quite complicated in the sense that they are 
    showing you how to create a color configuration UI in an extensible fashion. 
    You can create a simpler version of the same, using the ideas presented in 
    this article.
    
    Thanks,
    -Unni
    -- 
    This posting is provided "AS IS" with no warranties, and confers no rights.
    "Bela Istok" <bela_i@hotmail.com> wrote in message 
    news:C91CBACB-AF06-442C-97A3-3A905D252E47@microsoft.com...
    > How I can databind 3 slider's to represent an collor in other control, 
    > below
    > are my code.
    >
    >
    > -- 
    > Bela Istok
    >
    > <Grid
    > xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    > xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    > xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    > xmlns:d="http://schemas.microsoft.com/expression/interactivedesigner/2006"
    > Background="#FFFFFFFF"
    > x:Name="DocumentRoot"
    > Width="480" Height="480">
    > <Grid.Resources>
    > </Grid.Resources>
    >
    > <Grid.Triggers>
    > </Grid.Triggers>
    >
    > <Grid.ColumnDefinitions>
    > <ColumnDefinition/>
    > </Grid.ColumnDefinitions>
    > <Grid.RowDefinitions>
    > <RowDefinition/>
    > </Grid.RowDefinitions>
    > <DockPanel>
    >
    >
    >        <DockPanel Width="33.3">
    >            <TextBlock DockPanel.Dock="Top" 
    > Foreground="Red">Red</TextBlock>
    >            <TextBlock DockPanel.Dock="Bottom" Foreground="Red"
    > Text="{Binding Value, ElementName=redS, Mode=Default}" />
    >            <Slider x:Name="redS" Orientation="Vertical" Maximum="255"
    > SmallChange="1" />
    >        </DockPanel>
    >
    >        <DockPanel Width="33.3">
    >            <TextBlock DockPanel.Dock="Top"
    > Foreground="Green">Green</TextBlock>
    >            <TextBlock DockPanel.Dock="Bottom" Foreground="Green"
    > Text="{Binding Value, ElementName=greenS, Mode=Default}" />
    >            <Slider x:Name="greenS" Orientation="Vertical" Maximum="255"
    > SmallChange="1" />
    >        </DockPanel>
    >
    >        <DockPanel Width="33.3">
    >            <TextBlock DockPanel.Dock="Top" 
    > Foreground="Blue">Blue</TextBlock>
    >            <TextBlock DockPanel.Dock="Bottom" Foreground="Blue" Text
    > ="{Binding Value, ElementName=blueS, Mode=Default}"/>
    >            <Slider x:Name="blueS" Orientation="Vertical" Maximum="255"
    > SmallChange="1" />
    >        </DockPanel>
    >
    >
    >    <TextBlock DockPanel.Dock="Left"
    >               Width="353.05" Background="#FF000000"/>
    > </DockPanel>
    > </Grid> 
    
    
    
    Tuesday, February 19, 2008 6:01 PM
  • By: Bela Istok

    Would be nice that one can do this without code, only seting properties in 
    the XAML code.
    
    -- 
    Bela Istok
    
    
    "Unni Ravindranathan (MS)" wrote:
    
    > Hi Bela,
    > 
    > The WPF SDK walks you thru this exact scenario in a detailed fashion that 
    > you will find very informative:
    > 
    > http://windowssdk.msdn.microsoft.com/library/en-us/wpf_conceptual/html/ecb97ed4-e659-48a4-a1e0-893309569f2f.asp
    > 
    > Please note that this sample is quite complicated in the sense that they are 
    > showing you how to create a color configuration UI in an extensible fashion. 
    > You can create a simpler version of the same, using the ideas presented in 
    > this article.
    > 
    > Thanks,
    > -Unni
    > -- 
    > This posting is provided "AS IS" with no warranties, and confers no rights.
    > "Bela Istok" <bela_i@hotmail.com> wrote in message 
    > news:C91CBACB-AF06-442C-97A3-3A905D252E47@microsoft.com...
    > > How I can databind 3 slider's to represent an collor in other control, 
    > > below
    > > are my code.
    > >
    > >
    > > -- 
    > > Bela Istok
    > >
    > > <Grid
    > > xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    > > xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    > > xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    > > xmlns:d="http://schemas.microsoft.com/expression/interactivedesigner/2006"
    > > Background="#FFFFFFFF"
    > > x:Name="DocumentRoot"
    > > Width="480" Height="480">
    > > <Grid.Resources>
    > > </Grid.Resources>
    > >
    > > <Grid.Triggers>
    > > </Grid.Triggers>
    > >
    > > <Grid.ColumnDefinitions>
    > > <ColumnDefinition/>
    > > </Grid.ColumnDefinitions>
    > > <Grid.RowDefinitions>
    > > <RowDefinition/>
    > > </Grid.RowDefinitions>
    > > <DockPanel>
    > >
    > >
    > >        <DockPanel Width="33.3">
    > >            <TextBlock DockPanel.Dock="Top" 
    > > Foreground="Red">Red</TextBlock>
    > >            <TextBlock DockPanel.Dock="Bottom" Foreground="Red"
    > > Text="{Binding Value, ElementName=redS, Mode=Default}" />
    > >            <Slider x:Name="redS" Orientation="Vertical" Maximum="255"
    > > SmallChange="1" />
    > >        </DockPanel>
    > >
    > >        <DockPanel Width="33.3">
    > >            <TextBlock DockPanel.Dock="Top"
    > > Foreground="Green">Green</TextBlock>
    > >            <TextBlock DockPanel.Dock="Bottom" Foreground="Green"
    > > Text="{Binding Value, ElementName=greenS, Mode=Default}" />
    > >            <Slider x:Name="greenS" Orientation="Vertical" Maximum="255"
    > > SmallChange="1" />
    > >        </DockPanel>
    > >
    > >        <DockPanel Width="33.3">
    > >            <TextBlock DockPanel.Dock="Top" 
    > > Foreground="Blue">Blue</TextBlock>
    > >            <TextBlock DockPanel.Dock="Bottom" Foreground="Blue" Text
    > > ="{Binding Value, ElementName=blueS, Mode=Default}"/>
    > >            <Slider x:Name="blueS" Orientation="Vertical" Maximum="255"
    > > SmallChange="1" />
    > >        </DockPanel>
    > >
    > >
    > >    <TextBlock DockPanel.Dock="Left"
    > >               Width="353.05" Background="#FF000000"/>
    > > </DockPanel>
    > > </Grid> 
    > 
    > 
    > 
    Tuesday, February 19, 2008 6:01 PM
  • By: George Georgiev

    Hi Bela,

    I can't do it without code, but if you are interested how to do it with a
    minimum code, here is what I propose. Put this code in your code behind
    file:

    private void OnSliderValueChanged(object sender,
    System.Windows.RoutedPropertyChangedEventArgs<double> e)
    {
    myColoredFriend.Background = new
    SolidColorBrush(Color.FromRgb((byte)redS.Value, (byte)greenS.Value,
    (byte)blueS.Value));
    }

    I named your target textbox, myColoredFriend. The only thing you have to do
    is set the ValueChanged event of blueS, greenS and redS to call the
    OnSliderValueChanged method. It is always better to have a custom control,
    but I think this is easier to understand.

    The problem is you can't bind properties of different types unless you have
    a convertor. I would really like to see some common convertors built-in, so
    we can do more without compiled code.

    -- george --

    "Bela Istok" <bela_i@hotmail.com> wrote in message
    news:028E13F2-ECE6-404B-81A4-AAB594B26CF9@microsoft.com...
    > Would be nice that one can do this without code, only seting properties in
    > the XAML code.
    >
    > --
    > Bela Istok
    >
    >
    > "Unni Ravindranathan (MS)" wrote:
    >
    >> Hi Bela,
    >>
    >> The WPF SDK walks you thru this exact scenario in a detailed fashion that
    >> you will find very informative:
    >>
    >>
    http://windowssdk.msdn.microsoft.com/library/en-us/wpf_conceptual/html/ecb97ed4-e659-48a4-a1e0-893309569f2f.asp
    >>
    >> Please note that this sample is quite complicated in the sense that they
    >> are
    >> showing you how to create a color configuration UI in an extensible
    >> fashion.
    >> You can create a simpler version of the same, using the ideas presented
    >> in
    >> this article.
    >>
    >> Thanks,
    >> -Unni
    >> --
    >> This posting is provided "AS IS" with no warranties, and confers no
    >> rights.
    >> "Bela Istok" <bela_i@hotmail.com> wrote in message
    >> news:C91CBACB-AF06-442C-97A3-3A905D252E47@microsoft.com...
    >> > How I can databind 3 slider's to represent an collor in other control,
    >> > below
    >> > are my code.
    >> >
    >> >
    >> > --
    >> > Bela Istok
    >> >
    >> > <Grid
    >> > xmlns="
    http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    >> > xmlns:x="
    http://schemas.microsoft.com/winfx/2006/xaml"
    >> > xmlns:mc="
    http://schemas.openxmlformats.org/markup-compatibility/2006"
    >> > xmlns:d="
    http://schemas.microsoft.com/expression/interactivedesigner/2006"
    >> > Background="#FFFFFFFF"
    >> > x:Name="DocumentRoot"
    >> > Width="480" Height="480">
    >> > <Grid.Resources>
    >> > </Grid.Resources>
    >> >
    >> > <Grid.Triggers>
    >> > </Grid.Triggers>
    >> >
    >> > <Grid.ColumnDefinitions>
    >> > <ColumnDefinition/>
    >> > </Grid.ColumnDefinitions>
    >> > <Grid.RowDefinitions>
    >> > <RowDefinition/>
    >> > </Grid.RowDefinitions>
    >> > <DockPanel>
    >> >
    >> >
    >> > <DockPanel Width="33.3">
    >> > <TextBlock DockPanel.Dock="Top"
    >> > Foreground="Red">Red</TextBlock>
    >> > <TextBlock DockPanel.Dock="Bottom" Foreground="Red"
    >> > Text="{Binding Value, ElementName=redS, Mode=Default}" />
    >> > <Slider x:Name="redS" Orientation="Vertical" Maximum="255"
    >> > SmallChange="1" />
    >> > </DockPanel>
    >> >
    >> > <DockPanel Width="33.3">
    >> > <TextBlock DockPanel.Dock="Top"
    >> > Foreground="Green">Green</TextBlock>
    >> > <TextBlock DockPanel.Dock="Bottom" Foreground="Green"
    >> > Text="{Binding Value, ElementName=greenS, Mode=Default}" />
    >> > <Slider x:Name="greenS" Orientation="Vertical" Maximum="255"
    >> > SmallChange="1" />
    >> > </DockPanel>
    >> >
    >> > <DockPanel Width="33.3">
    >> > <TextBlock DockPanel.Dock="Top"
    >> > Foreground="Blue">Blue</TextBlock>
    >> > <TextBlock DockPanel.Dock="Bottom" Foreground="Blue" Text
    >> > ="{Binding Value, ElementName=blueS, Mode=Default}"/>
    >> > <Slider x:Name="blueS" Orientation="Vertical" Maximum="255"
    >> > SmallChange="1" />
    >> > </DockPanel>
    >> >
    >> >
    >> > <TextBlock DockPanel.Dock="Left"
    >> > Width="353.05" Background="#FF000000"/>
    >> > </DockPanel>
    >> > </Grid>
    >>
    >>
    >>

    Tuesday, February 19, 2008 6:01 PM
  • By: Bela Istok

    George, Thanks for you answer, you code is great for this simple example, but 
    I would love one can do this out the box. One can use simple binding, in 
    XAML, there will be more powerfull if one can do Multibinding rigth in the 
    XAML code. :D
    
    Regards,
    
    -- 
    Bela Istok
    
    
    "George Georgiev" wrote:
    
    > Hi Bela,
    > 
    > I can't do it without code, but if you are interested how to do it with a 
    > minimum code, here is what I propose. Put this code in your code behind 
    > file:
    > 
    >   private void OnSliderValueChanged(object sender, 
    > System.Windows.RoutedPropertyChangedEventArgs<double> e)
    >   {
    >    myColoredFriend.Background = new 
    > SolidColorBrush(Color.FromRgb((byte)redS.Value, (byte)greenS.Value, 
    > (byte)blueS.Value));
    >   }
    > 
    > I named your target textbox, myColoredFriend. The only thing you have to do 
    > is set the ValueChanged event of blueS, greenS and redS to call the 
    > OnSliderValueChanged method. It is always better to have a custom control, 
    > but I think this is easier to understand.
    > 
    > The problem is you can't bind properties of different types unless you have 
    > a convertor. I would really like to see some common convertors built-in, so 
    > we can do more without compiled code.
    > 
    > -- george --
    > 
    > "Bela Istok" <bela_i@hotmail.com> wrote in message 
    > news:028E13F2-ECE6-404B-81A4-AAB594B26CF9@microsoft.com...
    > > Would be nice that one can do this without code, only seting properties in
    > > the XAML code.
    > >
    > > -- 
    > > Bela Istok
    > >
    > >
    > > "Unni Ravindranathan (MS)" wrote:
    > >
    > >> Hi Bela,
    > >>
    > >> The WPF SDK walks you thru this exact scenario in a detailed fashion that
    > >> you will find very informative:
    > >>
    > >> http://windowssdk.msdn.microsoft.com/library/en-us/wpf_conceptual/html/ecb97ed4-e659-48a4-a1e0-893309569f2f.asp
    > >>
    > >> Please note that this sample is quite complicated in the sense that they 
    > >> are
    > >> showing you how to create a color configuration UI in an extensible 
    > >> fashion.
    > >> You can create a simpler version of the same, using the ideas presented 
    > >> in
    > >> this article.
    > >>
    > >> Thanks,
    > >> -Unni
    > >> -- 
    > >> This posting is provided "AS IS" with no warranties, and confers no 
    > >> rights.
    > >> "Bela Istok" <bela_i@hotmail.com> wrote in message
    > >> news:C91CBACB-AF06-442C-97A3-3A905D252E47@microsoft.com...
    > >> > How I can databind 3 slider's to represent an collor in other control,
    > >> > below
    > >> > are my code.
    > >> >
    > >> >
    > >> > -- 
    > >> > Bela Istok
    > >> >
    > >> > <Grid
    > >> > xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    > >> > xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    > >> > xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    > >> > xmlns:d="http://schemas.microsoft.com/expression/interactivedesigner/2006"
    > >> > Background="#FFFFFFFF"
    > >> > x:Name="DocumentRoot"
    > >> > Width="480" Height="480">
    > >> > <Grid.Resources>
    > >> > </Grid.Resources>
    > >> >
    > >> > <Grid.Triggers>
    > >> > </Grid.Triggers>
    > >> >
    > >> > <Grid.ColumnDefinitions>
    > >> > <ColumnDefinition/>
    > >> > </Grid.ColumnDefinitions>
    > >> > <Grid.RowDefinitions>
    > >> > <RowDefinition/>
    > >> > </Grid.RowDefinitions>
    > >> > <DockPanel>
    > >> >
    > >> >
    > >> >        <DockPanel Width="33.3">
    > >> >            <TextBlock DockPanel.Dock="Top"
    > >> > Foreground="Red">Red</TextBlock>
    > >> >            <TextBlock DockPanel.Dock="Bottom" Foreground="Red"
    > >> > Text="{Binding Value, ElementName=redS, Mode=Default}" />
    > >> >            <Slider x:Name="redS" Orientation="Vertical" Maximum="255"
    > >> > SmallChange="1" />
    > >> >        </DockPanel>
    > >> >
    > >> >        <DockPanel Width="33.3">
    > >> >            <TextBlock DockPanel.Dock="Top"
    > >> > Foreground="Green">Green</TextBlock>
    > >> >            <TextBlock DockPanel.Dock="Bottom" Foreground="Green"
    > >> > Text="{Binding Value, ElementName=greenS, Mode=Default}" />
    > >> >            <Slider x:Name="greenS" Orientation="Vertical" Maximum="255"
    > >> > SmallChange="1" />
    > >> >        </DockPanel>
    > >> >
    > >> >        <DockPanel Width="33.3">
    > >> >            <TextBlock DockPanel.Dock="Top"
    > >> > Foreground="Blue">Blue</TextBlock>
    > >> >            <TextBlock DockPanel.Dock="Bottom" Foreground="Blue" Text
    > >> > ="{Binding Value, ElementName=blueS, Mode=Default}"/>
    > >> >            <Slider x:Name="blueS" Orientation="Vertical" Maximum="255"
    > >> > SmallChange="1" />
    > >> >        </DockPanel>
    > >> >
    > >> >
    > >> >    <TextBlock DockPanel.Dock="Left"
    > >> >               Width="353.05" Background="#FF000000"/>
    > >> > </DockPanel>
    > >> > </Grid>
    > >>
    > >>
    > >> 
    > 
    > 
    > 
    Tuesday, February 19, 2008 6:02 PM
  • By: George Georgiev

    Well you can do multibinding from XAML, but you need the right converters, 
    which are defined in code. It will be nice if they ship the framework with a 
    prebuilt set of converters. Here is how you create a converter that will 
    convert 3 double color values into a Color object that you need to paint the 
    background of the textblock:
    
     public class DoubleColorMultiConverter : IMultiValueConverter
     {
    
          public object Convert(object[] values, Type targetType, object 
    parameter, System.Globalization.CultureInfo culture)
          {
    
              byte red = (byte)(double)values[0];
              byte green = (byte)(double)values[1];
              byte blue = (byte)(double)values[2];
    
              return Color.FromRgb(red, green, blue);
          }
    
          public object[] ConvertBack(object value, Type[] targetTypes, object 
    parameter, System.Globalization.CultureInfo culture)
          {
              Color color = (Color)value;
    
              return new object[] { color.R, color.G, color.B };
          }
     }
    
    
    Then you can use this in a multi binding XAML expression:
    
      <TextBlock DockPanel.Dock="Left" Width="353.05" x:Name="myColoredFriend">
        <TextBlock.Background>
    
       <SolidColorBrush>
       <SolidColorBrush.Color>
             <MultiBinding Converter="{StaticResource doubleToColorConverter}">
                <Binding Path="Value" ElementName="redS"/>
                <Binding Path="Value" ElementName="greenS"/>
                <Binding Path="Value" ElementName="blueS"/>
            </MultiBinding>
           </SolidColorBrush.Color>
       </SolidColorBrush>
    
        </TextBlock.Background>
        </TextBlock>
    
    The doubleToColorConverter static resource is defined as a resource of the 
    root element. Here is how my scene begins:
    
    <Grid
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
     xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
     xmlns:d="http://schemas.microsoft.com/expression/interactivedesigner/2006"
     xmlns:src="clr-namespace:UntitledProject1"
     mc:Ignorable="d"
     Background="#FFFFFFFF"
     x:Name="DocumentRoot"
     x:Class="UntitledProject1.Scene3"
     Width="640" Height="480">
    
     <Grid.Resources>
      <src:DoubleColorMultiConverter x:Key="doubleToColorConverter"/>
     </Grid.Resources>
    
    you need to replace UntitledProject1 with your own namespace that you use.
    
    The beauty of this aproach is that the converter is generic and you can use 
    it in all situations you need double to color conversions and also you get a 
    live preview inside the designer if you use converters. So if you manually 
    set the value of one of the sliders to some value you will see that the 
    background of the textblock changes in the designer.
    
    I certainly would like to see some of these conversions prepackaged with the 
    framework and if they decide to do it, I think double to color definatly 
    should be one of these.
    
    Sorry for the long reply. I hope this helps :)
    
    "Bela Istok" <bela_i@hotmail.com> wrote in message 
    news:017BD9E6-BBDE-4819-8555-487EC891500A@microsoft.com...
    > George, Thanks for you answer, you code is great for this simple example, 
    > but
    > I would love one can do this out the box. One can use simple binding, in
    > XAML, there will be more powerfull if one can do Multibinding rigth in the
    > XAML code. :D
    >
    > Regards,
    >
    > -- 
    > Bela Istok
    >
    >
    > "George Georgiev" wrote:
    >
    >> Hi Bela,
    >>
    >> I can't do it without code, but if you are interested how to do it with a
    >> minimum code, here is what I propose. Put this code in your code behind
    >> file:
    >>
    >>   private void OnSliderValueChanged(object sender,
    >> System.Windows.RoutedPropertyChangedEventArgs<double> e)
    >>   {
    >>    myColoredFriend.Background = new
    >> SolidColorBrush(Color.FromRgb((byte)redS.Value, (byte)greenS.Value,
    >> (byte)blueS.Value));
    >>   }
    >>
    >> I named your target textbox, myColoredFriend. The only thing you have to 
    >> do
    >> is set the ValueChanged event of blueS, greenS and redS to call the
    >> OnSliderValueChanged method. It is always better to have a custom 
    >> control,
    >> but I think this is easier to understand.
    >>
    >> The problem is you can't bind properties of different types unless you 
    >> have
    >> a convertor. I would really like to see some common convertors built-in, 
    >> so
    >> we can do more without compiled code.
    >>
    >> -- george --
    >>
    >> "Bela Istok" <bela_i@hotmail.com> wrote in message
    >> news:028E13F2-ECE6-404B-81A4-AAB594B26CF9@microsoft.com...
    >> > Would be nice that one can do this without code, only seting properties 
    >> > in
    >> > the XAML code.
    >> >
    >> > -- 
    >> > Bela Istok
    >> >
    >> >
    >> > "Unni Ravindranathan (MS)" wrote:
    >> >
    >> >> Hi Bela,
    >> >>
    >> >> The WPF SDK walks you thru this exact scenario in a detailed fashion 
    >> >> that
    >> >> you will find very informative:
    >> >>
    >> >> http://windowssdk.msdn.microsoft.com/library/en-us/wpf_conceptual/html/ecb97ed4-e659-48a4-a1e0-893309569f2f.asp
    >> >>
    >> >> Please note that this sample is quite complicated in the sense that 
    >> >> they
    >> >> are
    >> >> showing you how to create a color configuration UI in an extensible
    >> >> fashion.
    >> >> You can create a simpler version of the same, using the ideas 
    >> >> presented
    >> >> in
    >> >> this article.
    >> >>
    >> >> Thanks,
    >> >> -Unni
    >> >> -- 
    >> >> This posting is provided "AS IS" with no warranties, and confers no
    >> >> rights.
    >> >> "Bela Istok" <bela_i@hotmail.com> wrote in message
    >> >> news:C91CBACB-AF06-442C-97A3-3A905D252E47@microsoft.com...
    >> >> > How I can databind 3 slider's to represent an collor in other 
    >> >> > control,
    >> >> > below
    >> >> > are my code.
    >> >> >
    >> >> >
    >> >> > -- 
    >> >> > Bela Istok
    >> >> >
    >> >> > <Grid
    >> >> > xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    >> >> > xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    >> >> > xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    >> >> > xmlns:d="http://schemas.microsoft.com/expression/interactivedesigner/2006"
    >> >> > Background="#FFFFFFFF"
    >> >> > x:Name="DocumentRoot"
    >> >> > Width="480" Height="480">
    >> >> > <Grid.Resources>
    >> >> > </Grid.Resources>
    >> >> >
    >> >> > <Grid.Triggers>
    >> >> > </Grid.Triggers>
    >> >> >
    >> >> > <Grid.ColumnDefinitions>
    >> >> > <ColumnDefinition/>
    >> >> > </Grid.ColumnDefinitions>
    >> >> > <Grid.RowDefinitions>
    >> >> > <RowDefinition/>
    >> >> > </Grid.RowDefinitions>
    >> >> > <DockPanel>
    >> >> >
    >> >> >
    >> >> >        <DockPanel Width="33.3">
    >> >> >            <TextBlock DockPanel.Dock="Top"
    >> >> > Foreground="Red">Red</TextBlock>
    >> >> >            <TextBlock DockPanel.Dock="Bottom" Foreground="Red"
    >> >> > Text="{Binding Value, ElementName=redS, Mode=Default}" />
    >> >> >            <Slider x:Name="redS" Orientation="Vertical" 
    >> >> > Maximum="255"
    >> >> > SmallChange="1" />
    >> >> >        </DockPanel>
    >> >> >
    >> >> >        <DockPanel Width="33.3">
    >> >> >            <TextBlock DockPanel.Dock="Top"
    >> >> > Foreground="Green">Green</TextBlock>
    >> >> >            <TextBlock DockPanel.Dock="Bottom" Foreground="Green"
    >> >> > Text="{Binding Value, ElementName=greenS, Mode=Default}" />
    >> >> >            <Slider x:Name="greenS" Orientation="Vertical" 
    >> >> > Maximum="255"
    >> >> > SmallChange="1" />
    >> >> >        </DockPanel>
    >> >> >
    >> >> >        <DockPanel Width="33.3">
    >> >> >            <TextBlock DockPanel.Dock="Top"
    >> >> > Foreground="Blue">Blue</TextBlock>
    >> >> >            <TextBlock DockPanel.Dock="Bottom" Foreground="Blue" Text
    >> >> > ="{Binding Value, ElementName=blueS, Mode=Default}"/>
    >> >> >            <Slider x:Name="blueS" Orientation="Vertical" 
    >> >> > Maximum="255"
    >> >> > SmallChange="1" />
    >> >> >        </DockPanel>
    >> >> >
    >> >> >
    >> >> >    <TextBlock DockPanel.Dock="Left"
    >> >> >               Width="353.05" Background="#FF000000"/>
    >> >> > </DockPanel>
    >> >> > </Grid>
    >> >>
    >> >>
    >> >>
    >>
    >>
    >> 
    
    
    
    Tuesday, February 19, 2008 6:02 PM
  • By: Bela Istok

    I think the more ways we have the better, This MultiBinding Converter, is a 
    great step to the idea I have about XAML, and like you do, would be nice they 
    include a lot of converters before they ship.
    -- 
    Bela Istok
    
    
    "George Georgiev" wrote:
    
    > Well you can do multibinding from XAML, but you need the right converters, 
    > which are defined in code. It will be nice if they ship the framework with a 
    > prebuilt set of converters. Here is how you create a converter that will 
    > convert 3 double color values into a Color object that you need to paint the 
    > background of the textblock:
    > 
    >  public class DoubleColorMultiConverter : IMultiValueConverter
    >  {
    > 
    >       public object Convert(object[] values, Type targetType, object 
    > parameter, System.Globalization.CultureInfo culture)
    >       {
    > 
    >           byte red = (byte)(double)values[0];
    >           byte green = (byte)(double)values[1];
    >           byte blue = (byte)(double)values[2];
    > 
    >           return Color.FromRgb(red, green, blue);
    >       }
    > 
    >       public object[] ConvertBack(object value, Type[] targetTypes, object 
    > parameter, System.Globalization.CultureInfo culture)
    >       {
    >           Color color = (Color)value;
    > 
    >           return new object[] { color.R, color.G, color.B };
    >       }
    >  }
    > 
    > 
    > Then you can use this in a multi binding XAML expression:
    > 
    >   <TextBlock DockPanel.Dock="Left" Width="353.05" x:Name="myColoredFriend">
    >     <TextBlock.Background>
    > 
    >    <SolidColorBrush>
    >    <SolidColorBrush.Color>
    >          <MultiBinding Converter="{StaticResource doubleToColorConverter}">
    >             <Binding Path="Value" ElementName="redS"/>
    >             <Binding Path="Value" ElementName="greenS"/>
    >             <Binding Path="Value" ElementName="blueS"/>
    >         </MultiBinding>
    >        </SolidColorBrush.Color>
    >    </SolidColorBrush>
    > 
    >     </TextBlock.Background>
    >     </TextBlock>
    > 
    > The doubleToColorConverter static resource is defined as a resource of the 
    > root element. Here is how my scene begins:
    > 
    > <Grid
    >  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    >  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    >  xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    >  xmlns:d="http://schemas.microsoft.com/expression/interactivedesigner/2006"
    >  xmlns:src="clr-namespace:UntitledProject1"
    >  mc:Ignorable="d"
    >  Background="#FFFFFFFF"
    >  x:Name="DocumentRoot"
    >  x:Class="UntitledProject1.Scene3"
    >  Width="640" Height="480">
    > 
    >  <Grid.Resources>
    >   <src:DoubleColorMultiConverter x:Key="doubleToColorConverter"/>
    >  </Grid.Resources>
    > 
    > you need to replace UntitledProject1 with your own namespace that you use.
    > 
    > The beauty of this aproach is that the converter is generic and you can use 
    > it in all situations you need double to color conversions and also you get a 
    > live preview inside the designer if you use converters. So if you manually 
    > set the value of one of the sliders to some value you will see that the 
    > background of the textblock changes in the designer.
    > 
    > I certainly would like to see some of these conversions prepackaged with the 
    > framework and if they decide to do it, I think double to color definatly 
    > should be one of these.
    > 
    > Sorry for the long reply. I hope this helps :)
    > 
    > "Bela Istok" <bela_i@hotmail.com> wrote in message 
    > news:017BD9E6-BBDE-4819-8555-487EC891500A@microsoft.com...
    > > George, Thanks for you answer, you code is great for this simple example, 
    > > but
    > > I would love one can do this out the box. One can use simple binding, in
    > > XAML, there will be more powerfull if one can do Multibinding rigth in the
    > > XAML code. :D
    > >
    > > Regards,
    > >
    > > -- 
    > > Bela Istok
    > >
    > >
    > > "George Georgiev" wrote:
    > >
    > >> Hi Bela,
    > >>
    > >> I can't do it without code, but if you are interested how to do it with a
    > >> minimum code, here is what I propose. Put this code in your code behind
    > >> file:
    > >>
    > >>   private void OnSliderValueChanged(object sender,
    > >> System.Windows.RoutedPropertyChangedEventArgs<double> e)
    > >>   {
    > >>    myColoredFriend.Background = new
    > >> SolidColorBrush(Color.FromRgb((byte)redS.Value, (byte)greenS.Value,
    > >> (byte)blueS.Value));
    > >>   }
    > >>
    > >> I named your target textbox, myColoredFriend. The only thing you have to 
    > >> do
    > >> is set the ValueChanged event of blueS, greenS and redS to call the
    > >> OnSliderValueChanged method. It is always better to have a custom 
    > >> control,
    > >> but I think this is easier to understand.
    > >>
    > >> The problem is you can't bind properties of different types unless you 
    > >> have
    > >> a convertor. I would really like to see some common convertors built-in, 
    > >> so
    > >> we can do more without compiled code.
    > >>
    > >> -- george --
    > >>
    > >> "Bela Istok" <bela_i@hotmail.com> wrote in message
    > >> news:028E13F2-ECE6-404B-81A4-AAB594B26CF9@microsoft.com...
    > >> > Would be nice that one can do this without code, only seting properties 
    > >> > in
    > >> > the XAML code.
    > >> >
    > >> > -- 
    > >> > Bela Istok
    > >> >
    > >> >
    > >> > "Unni Ravindranathan (MS)" wrote:
    > >> >
    > >> >> Hi Bela,
    > >> >>
    > >> >> The WPF SDK walks you thru this exact scenario in a detailed fashion 
    > >> >> that
    > >> >> you will find very informative:
    > >> >>
    > >> >> http://windowssdk.msdn.microsoft.com/library/en-us/wpf_conceptual/html/ecb97ed4-e659-48a4-a1e0-893309569f2f.asp
    > >> >>
    > >> >> Please note that this sample is quite complicated in the sense that 
    > >> >> they
    > >> >> are
    > >> >> showing you how to create a color configuration UI in an extensible
    > >> >> fashion.
    > >> >> You can create a simpler version of the same, using the ideas 
    > >> >> presented
    > >> >> in
    > >> >> this article.
    > >> >>
    > >> >> Thanks,
    > >> >> -Unni
    > >> >> -- 
    > >> >> This posting is provided "AS IS" with no warranties, and confers no
    > >> >> rights.
    > >> >> "Bela Istok" <bela_i@hotmail.com> wrote in message
    > >> >> news:C91CBACB-AF06-442C-97A3-3A905D252E47@microsoft.com...
    > >> >> > How I can databind 3 slider's to represent an collor in other 
    > >> >> > control,
    > >> >> > below
    > >> >> > are my code.
    > >> >> >
    > >> >> >
    > >> >> > -- 
    > >> >> > Bela Istok
    > >> >> >
    > >> >> > <Grid
    > >> >> > xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    > >> >> > xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    > >> >> > xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    > >> >> > xmlns:d="http://schemas.microsoft.com/expression/interactivedesigner/2006"
    > >> >> > Background="#FFFFFFFF"
    > >> >> > x:Name="DocumentRoot"
    > >> >> > Width="480" Height="480">
    > >> >> > <Grid.Resources>
    > >> >> > </Grid.Resources>
    > >> >> >
    > >> >> > <Grid.Triggers>
    > >> >> > </Grid.Triggers>
    > >> >> >
    > >> >> > <Grid.ColumnDefinitions>
    > >> >> > <ColumnDefinition/>
    > >> >> > </Grid.ColumnDefinitions>
    > >> >> > <Grid.RowDefinitions>
    > >> >> > <RowDefinition/>
    > >> >> > </Grid.RowDefinitions>
    > >> >> > <DockPanel>
    > >> >> >
    > >> >> >
    > >> >> >        <DockPanel Width="33.3">
    > >> >> >            <TextBlock DockPanel.Dock="Top"
    > >> >> > Foreground="Red">Red</TextBlock>
    > >> >> >            <TextBlock DockPanel.Dock="Bottom" Foreground="Red"
    > >> >> > Text="{Binding Value, ElementName=redS, Mode=Default}" />
    > >> >> >            <Slider x:Name="redS" Orientation="Vertical" 
    > >> >> > Maximum="255"
    > >> >> > SmallChange="1" />
    > >> >> >        </DockPanel>
    > >> >> >
    > >> >> >        <DockPanel Width="33.3">
    > >> >> >            <TextBlock DockPanel.Dock="Top"
    > >> >> > Foreground="Green">Green</TextBlock>
    > >> >> >            <TextBlock DockPanel.Dock="Bottom" Foreground="Green"
    > >> >> > Text="{Binding Value, ElementName=greenS, Mode=Default}" />
    > >> >> >            <Slider x:Name="greenS" Orientation="Vertical" 
    > >> >> > Maximum="255"
    > >> >> > SmallChange="1" />
    > >> >> >        </DockPanel>
    > >> >> >
    > >> >> >        <DockPanel Width="33.3">
    > >> >> >            <TextBlock DockPanel.Dock="Top"
    > >> >> > Foreground="Blue">Blue</TextBlock>
    > >> >> >            <TextBlock DockPanel.Dock="Bottom" Foreground="Blue" Text
    > >> >> > ="{Binding Value, ElementName=blueS, Mode=Default}"/>
    > >> >> >            <Slider x:Name="blueS" Orientation="Vertical" 
    > >> >> > Maximum="255"
    > >> >> > SmallChange="1" />
    > >> >> >        </DockPanel>
    > >> >> >
    > >> >> >
    > >> >> >    <TextBlock DockPanel.Dock="Left"
    > >> >> >               Width="353.05" Background="#FF000000"/>
    > >> >> > </DockPanel>
    > >> >> > </Grid>
    > >> >>
    > >> >>
    > >> >>
    > >>
    > >>
    > >> 
    > 
    > 
    > 
    Tuesday, February 19, 2008 6:03 PM
  • By: Unni Ravindranathan (MS)

    I think George did a great job explaining with a really nice sample.
    Converters are the way to go there, and as he explains, they are great for
    sharing. You are correct in the fact that we would have liked to see many
    pre-built converters ship with the platform (we can def. ship a few with
    EID, but then you will have a dependency on a designer Dll that many people
    don't like, and something that we learn from our HTML experiences). I would
    think that as the tool and platform become more popular, there would be a
    significant contribution from the community in this area.

    Thanks,
    -Unni
    --
    This posting is provided "AS IS" with no warranties, and confers no rights.
    "Bela Istok" <bela_i@hotmail.com> wrote in message
    news:DF25F5A5-1AF3-44E5-9138-E9AF0BC1966F@microsoft.com...
    >I think the more ways we have the better, This MultiBinding Converter, is a
    > great step to the idea I have about XAML, and like you do, would be nice
    > they
    > include a lot of converters before they ship.
    > --
    > Bela Istok
    >
    >
    > "George Georgiev" wrote:
    >
    >> Well you can do multibinding from XAML, but you need the right
    >> converters,
    >> which are defined in code. It will be nice if they ship the framework
    >> with a
    >> prebuilt set of converters. Here is how you create a converter that will
    >> convert 3 double color values into a Color object that you need to paint
    >> the
    >> background of the textblock:
    >>
    >> public class DoubleColorMultiConverter : IMultiValueConverter
    >> {
    >>
    >> public object Convert(object[] values, Type targetType, object
    >> parameter, System.Globalization.CultureInfo culture)
    >> {
    >>
    >> byte red = (byte)(double)values[0];
    >> byte green = (byte)(double)values[1];
    >> byte blue = (byte)(double)values[2];
    >>
    >> return Color.FromRgb(red, green, blue);
    >> }
    >>
    >> public object[] ConvertBack(object value, Type[] targetTypes,
    >> object
    >> parameter, System.Globalization.CultureInfo culture)
    >> {
    >> Color color = (Color)value;
    >>
    >> return new object[] { color.R, color.G, color.B };
    >> }
    >> }
    >>
    >>
    >> Then you can use this in a multi binding XAML expression:
    >>
    >> <TextBlock DockPanel.Dock="Left" Width="353.05"
    >> x:Name="myColoredFriend">
    >> <TextBlock.Background>
    >>
    >> <SolidColorBrush>
    >> <SolidColorBrush.Color>
    >> <MultiBinding Converter="{StaticResource
    >> doubleToColorConverter}">
    >> <Binding Path="Value" ElementName="redS"/>
    >> <Binding Path="Value" ElementName="greenS"/>
    >> <Binding Path="Value" ElementName="blueS"/>
    >> </MultiBinding>
    >> </SolidColorBrush.Color>
    >> </SolidColorBrush>
    >>
    >> </TextBlock.Background>
    >> </TextBlock>
    >>
    >> The doubleToColorConverter static resource is defined as a resource of
    >> the
    >> root element. Here is how my scene begins:
    >>
    >> <Grid
    >> xmlns="
    http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    >> xmlns:x="
    http://schemas.microsoft.com/winfx/2006/xaml"
    >> xmlns:mc="
    http://schemas.openxmlformats.org/markup-compatibility/2006"
    >>
    >> xmlns:d="
    http://schemas.microsoft.com/expression/interactivedesigner/2006"
    >> xmlns:src="clr-namespace:UntitledProject1"
    >> mc:Ignorable="d"
    >> Background="#FFFFFFFF"
    >> x:Name="DocumentRoot"
    >> x:Class="UntitledProject1.Scene3"
    >> Width="640" Height="480">
    >>
    >> <Grid.Resources>
    >> <src:DoubleColorMultiConverter x:Key="doubleToColorConverter"/>
    >> </Grid.Resources>
    >>
    >> you need to replace UntitledProject1 with your own namespace that you
    >> use.
    >>
    >> The beauty of this aproach is that the converter is generic and you can
    >> use
    >> it in all situations you need double to color conversions and also you
    >> get a
    >> live preview inside the designer if you use converters. So if you
    >> manually
    >> set the value of one of the sliders to some value you will see that the
    >> background of the textblock changes in the designer.
    >>
    >> I certainly would like to see some of these conversions prepackaged with
    >> the
    >> framework and if they decide to do it, I think double to color definatly
    >> should be one of these.
    >>
    >> Sorry for the long reply. I hope this helps :)
    >>
    >> "Bela Istok" <bela_i@hotmail.com> wrote in message
    >> news:017BD9E6-BBDE-4819-8555-487EC891500A@microsoft.com...
    >> > George, Thanks for you answer, you code is great for this simple
    >> > example,
    >> > but
    >> > I would love one can do this out the box. One can use simple binding,
    >> > in
    >> > XAML, there will be more powerfull if one can do Multibinding rigth in
    >> > the
    >> > XAML code. :D
    >> >
    >> > Regards,
    >> >
    >> > --
    >> > Bela Istok
    >> >
    >> >
    >> > "George Georgiev" wrote:
    >> >
    >> >> Hi Bela,
    >> >>
    >> >> I can't do it without code, but if you are interested how to do it
    >> >> with a
    >> >> minimum code, here is what I propose. Put this code in your code
    >> >> behind
    >> >> file:
    >> >>
    >> >> private void OnSliderValueChanged(object sender,
    >> >> System.Windows.RoutedPropertyChangedEventArgs<double> e)
    >> >> {
    >> >> myColoredFriend.Background = new
    >> >> SolidColorBrush(Color.FromRgb((byte)redS.Value, (byte)greenS.Value,
    >> >> (byte)blueS.Value));
    >> >> }
    >> >>
    >> >> I named your target textbox, myColoredFriend. The only thing you have
    >> >> to
    >> >> do
    >> >> is set the ValueChanged event of blueS, greenS and redS to call the
    >> >> OnSliderValueChanged method. It is always better to have a custom
    >> >> control,
    >> >> but I think this is easier to understand.
    >> >>
    >> >> The problem is you can't bind properties of different types unless you
    >> >> have
    >> >> a convertor. I would really like to see some common convertors
    >> >> built-in,
    >> >> so
    >> >> we can do more without compiled code.
    >> >>
    >> >> -- george --
    >> >>
    >> >> "Bela Istok" <bela_i@hotmail.com> wrote in message
    >> >> news:028E13F2-ECE6-404B-81A4-AAB594B26CF9@microsoft.com...
    >> >> > Would be nice that one can do this without code, only seting
    >> >> > properties
    >> >> > in
    >> >> > the XAML code.
    >> >> >
    >> >> > --
    >> >> > Bela Istok
    >> >> >
    >> >> >
    >> >> > "Unni Ravindranathan (MS)" wrote:
    >> >> >
    >> >> >> Hi Bela,
    >> >> >>
    >> >> >> The WPF SDK walks you thru this exact scenario in a detailed
    >> >> >> fashion
    >> >> >> that
    >> >> >> you will find very informative:
    >> >> >>
    >> >> >>
    http://windowssdk.msdn.microsoft.com/library/en-us/wpf_conceptual/html/ecb97ed4-e659-48a4-a1e0-893309569f2f.asp
    >> >> >>
    >> >> >> Please note that this sample is quite complicated in the sense that
    >> >> >> they
    >> >> >> are
    >> >> >> showing you how to create a color configuration UI in an extensible
    >> >> >> fashion.
    >> >> >> You can create a simpler version of the same, using the ideas
    >> >> >> presented
    >> >> >> in
    >> >> >> this article.
    >> >> >>
    >> >> >> Thanks,
    >> >> >> -Unni
    >> >> >> --
    >> >> >> This posting is provided "AS IS" with no warranties, and confers no
    >> >> >> rights.
    >> >> >> "Bela Istok" <bela_i@hotmail.com> wrote in message
    >> >> >> news:C91CBACB-AF06-442C-97A3-3A905D252E47@microsoft.com...
    >> >> >> > How I can databind 3 slider's to represent an collor in other
    >> >> >> > control,
    >> >> >> > below
    >> >> >> > are my code.
    >> >> >> >
    >> >> >> >
    >> >> >> > --
    >> >> >> > Bela Istok
    >> >> >> >
    >> >> >> > <Grid
    >> >> >> > xmlns="
    http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    >> >> >> > xmlns:x="
    http://schemas.microsoft.com/winfx/2006/xaml"
    >> >> >> > xmlns:mc="
    http://schemas.openxmlformats.org/markup-compatibility/2006"
    >> >> >> > xmlns:d="
    http://schemas.microsoft.com/expression/interactivedesigner/2006"
    >> >> >> > Background="#FFFFFFFF"
    >> >> >> > x:Name="DocumentRoot"
    >> >> >> > Width="480" Height="480">
    >> >> >> > <Grid.Resources>
    >> >> >> > </Grid.Resources>
    >> >> >> >
    >> >> >> > <Grid.Triggers>
    >> >> >> > </Grid.Triggers>
    >> >> >> >
    >> >> >> > <Grid.ColumnDefinitions>
    >> >> >> > <ColumnDefinition/>
    >> >> >> > </Grid.ColumnDefinitions>
    >> >> >> > <Grid.RowDefinitions>
    >> >> >> > <RowDefinition/>
    >> >> >> > </Grid.RowDefinitions>
    >> >> >> > <DockPanel>
    >> >> >> >
    >> >> >> >
    >> >> >> > <DockPanel Width="33.3">
    >> >> >> > <TextBlock DockPanel.Dock="Top"
    >> >> >> > Foreground="Red">Red</TextBlock>
    >> >> >> > <TextBlock DockPanel.Dock="Bottom" Foreground="Red"
    >> >> >> > Text="{Binding Value, ElementName=redS, Mode=Default}" />
    >> >> >> > <Slider x:Name="redS" Orientation="Vertical"
    >> >> >> > Maximum="255"
    >> >> >> > SmallChange="1" />
    >> >> >> > </DockPanel>
    >> >> >> >
    >> >> >> > <DockPanel Width="33.3">
    >> >> >> > <TextBlock DockPanel.Dock="Top"
    >> >> >> > Foreground="Green">Green</TextBlock>
    >> >> >> > <TextBlock DockPanel.Dock="Bottom" Foreground="Green"
    >> >> >> > Text="{Binding Value, ElementName=greenS, Mode=Default}" />
    >> >> >> > <Slider x:Name="greenS" Orientation="Vertical"
    >> >> >> > Maximum="255"
    >> >> >> > SmallChange="1" />
    >> >> >> > </DockPanel>
    >> >> >> >
    >> >> >> > <DockPanel Width="33.3">
    >> >> >> > <TextBlock DockPanel.Dock="Top"
    >> >> >> > Foreground="Blue">Blue</TextBlock>
    >> >> >> > <TextBlock DockPanel.Dock="Bottom" Foreground="Blue"
    >> >> >> > Text
    >> >> >> > ="{Binding Value, ElementName=blueS, Mode=Default}"/>
    >> >> >> > <Slider x:Name="blueS" Orientation="Vertical"
    >> >> >> > Maximum="255"
    >> >> >> > SmallChange="1" />
    >> >> >> > </DockPanel>
    >> >> >> >
    >> >> >> >
    >> >> >> > <TextBlock DockPanel.Dock="Left"
    >> >> >> > Width="353.05" Background="#FF000000"/>
    >> >> >> > </DockPanel>
    >> >> >> > </Grid>
    >> >> >>
    >> >> >>
    >> >> >>
    >> >>
    >> >>
    >> >>
    >>
    >>
    >>
    Tuesday, February 19, 2008 6:03 PM
  • By: George Georgiev

    I think they are nice to have, but not a show stopper. The value of
    pre-built converters is that you can do more in XAML. But I think that
    virtually all apps will require some kind of satellite files to run, so you
    can definitely throw the compiled converters among them. So basically it
    will be mainly nice to have those, so you can show how much you can do in
    XML ;)



    "Unni Ravindranathan (MS)" <unnir@online.microsoft.com> wrote in message
    news:OXKby3WkGHA.4528@TK2MSFTNGP05.phx.gbl...
    >I think George did a great job explaining with a really nice sample.
    >Converters are the way to go there, and as he explains, they are great for
    >sharing. You are correct in the fact that we would have liked to see many
    >pre-built converters ship with the platform (we can def. ship a few with
    >EID, but then you will have a dependency on a designer Dll that many people
    >don't like, and something that we learn from our HTML experiences). I would
    >think that as the tool and platform become more popular, there would be a
    >significant contribution from the community in this area.
    >
    > Thanks,
    > -Unni
    > --
    > This posting is provided "AS IS" with no warranties, and confers no
    > rights.
    > "Bela Istok" <bela_i@hotmail.com> wrote in message
    > news:DF25F5A5-1AF3-44E5-9138-E9AF0BC1966F@microsoft.com...
    >>I think the more ways we have the better, This MultiBinding Converter, is
    >>a
    >> great step to the idea I have about XAML, and like you do, would be nice
    >> they
    >> include a lot of converters before they ship.
    >> --
    >> Bela Istok
    >>
    >>
    >> "George Georgiev" wrote:
    >>
    >>> Well you can do multibinding from XAML, but you need the right
    >>> converters,
    >>> which are defined in code. It will be nice if they ship the framework
    >>> with a
    >>> prebuilt set of converters. Here is how you create a converter that will
    >>> convert 3 double color values into a Color object that you need to paint
    >>> the
    >>> background of the textblock:
    >>>
    >>> public class DoubleColorMultiConverter : IMultiValueConverter
    >>> {
    >>>
    >>> public object Convert(object[] values, Type targetType, object
    >>> parameter, System.Globalization.CultureInfo culture)
    >>> {
    >>>
    >>> byte red = (byte)(double)values[0];
    >>> byte green = (byte)(double)values[1];
    >>> byte blue = (byte)(double)values[2];
    >>>
    >>> return Color.FromRgb(red, green, blue);
    >>> }
    >>>
    >>> public object[] ConvertBack(object value, Type[] targetTypes,
    >>> object
    >>> parameter, System.Globalization.CultureInfo culture)
    >>> {
    >>> Color color = (Color)value;
    >>>
    >>> return new object[] { color.R, color.G, color.B };
    >>> }
    >>> }
    >>>
    >>>
    >>> Then you can use this in a multi binding XAML expression:
    >>>
    >>> <TextBlock DockPanel.Dock="Left" Width="353.05"
    >>> x:Name="myColoredFriend">
    >>> <TextBlock.Background>
    >>>
    >>> <SolidColorBrush>
    >>> <SolidColorBrush.Color>
    >>> <MultiBinding Converter="{StaticResource
    >>> doubleToColorConverter}">
    >>> <Binding Path="Value" ElementName="redS"/>
    >>> <Binding Path="Value" ElementName="greenS"/>
    >>> <Binding Path="Value" ElementName="blueS"/>
    >>> </MultiBinding>
    >>> </SolidColorBrush.Color>
    >>> </SolidColorBrush>
    >>>
    >>> </TextBlock.Background>
    >>> </TextBlock>
    >>>
    >>> The doubleToColorConverter static resource is defined as a resource of
    >>> the
    >>> root element. Here is how my scene begins:
    >>>
    >>> <Grid
    >>> xmlns="
    http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    >>> xmlns:x="
    http://schemas.microsoft.com/winfx/2006/xaml"
    >>> xmlns:mc="
    http://schemas.openxmlformats.org/markup-compatibility/2006"
    >>>
    >>> xmlns:d="
    http://schemas.microsoft.com/expression/interactivedesigner/2006"
    >>> xmlns:src="clr-namespace:UntitledProject1"
    >>> mc:Ignorable="d"
    >>> Background="#FFFFFFFF"
    >>> x:Name="DocumentRoot"
    >>> x:Class="UntitledProject1.Scene3"
    >>> Width="640" Height="480">
    >>>
    >>> <Grid.Resources>
    >>> <src:DoubleColorMultiConverter x:Key="doubleToColorConverter"/>
    >>> </Grid.Resources>
    >>>
    >>> you need to replace UntitledProject1 with your own namespace that you
    >>> use.
    >>>
    >>> The beauty of this aproach is that the converter is generic and you can
    >>> use
    >>> it in all situations you need double to color conversions and also you
    >>> get a
    >>> live preview inside the designer if you use converters. So if you
    >>> manually
    >>> set the value of one of the sliders to some value you will see that the
    >>> background of the textblock changes in the designer.
    >>>
    >>> I certainly would like to see some of these conversions prepackaged with
    >>> the
    >>> framework and if they decide to do it, I think double to color definatly
    >>> should be one of these.
    >>>
    >>> Sorry for the long reply. I hope this helps :)
    >>>
    >>> "Bela Istok" <bela_i@hotmail.com> wrote in message
    >>> news:017BD9E6-BBDE-4819-8555-487EC891500A@microsoft.com...
    >>> > George, Thanks for you answer, you code is great for this simple
    >>> > example,
    >>> > but
    >>> > I would love one can do this out the box. One can use simple binding,
    >>> > in
    >>> > XAML, there will be more powerfull if one can do Multibinding rigth in
    >>> > the
    >>> > XAML code. :D
    >>> >
    >>> > Regards,
    >>> >
    >>> > --
    >>> > Bela Istok
    >>> >
    >>> >
    >>> > "George Georgiev" wrote:
    >>> >
    >>> >> Hi Bela,
    >>> >>
    >>> >> I can't do it without code, but if you are interested how to do it
    >>> >> with a
    >>> >> minimum code, here is what I propose. Put this code in your code
    >>> >> behind
    >>> >> file:
    >>> >>
    >>> >> private void OnSliderValueChanged(object sender,
    >>> >> System.Windows.RoutedPropertyChangedEventArgs<double> e)
    >>> >> {
    >>> >> myColoredFriend.Background = new
    >>> >> SolidColorBrush(Color.FromRgb((byte)redS.Value, (byte)greenS.Value,
    >>> >> (byte)blueS.Value));
    >>> >> }
    >>> >>
    >>> >> I named your target textbox, myColoredFriend. The only thing you have
    >>> >> to
    >>> >> do
    >>> >> is set the ValueChanged event of blueS, greenS and redS to call the
    >>> >> OnSliderValueChanged method. It is always better to have a custom
    >>> >> control,
    >>> >> but I think this is easier to understand.
    >>> >>
    >>> >> The problem is you can't bind properties of different types unless
    >>> >> you
    >>> >> have
    >>> >> a convertor. I would really like to see some common convertors
    >>> >> built-in,
    >>> >> so
    >>> >> we can do more without compiled code.
    >>> >>
    >>> >> -- george --
    >>> >>
    >>> >> "Bela Istok" <bela_i@hotmail.com> wrote in message
    >>> >> news:028E13F2-ECE6-404B-81A4-AAB594B26CF9@microsoft.com...
    >>> >> > Would be nice that one can do this without code, only seting
    >>> >> > properties
    >>> >> > in
    >>> >> > the XAML code.
    >>> >> >
    >>> >> > --
    >>> >> > Bela Istok
    >>> >> >
    >>> >> >
    >>> >> > "Unni Ravindranathan (MS)" wrote:
    >>> >> >
    >>> >> >> Hi Bela,
    >>> >> >>
    >>> >> >> The WPF SDK walks you thru this exact scenario in a detailed
    >>> >> >> fashion
    >>> >> >> that
    >>> >> >> you will find very informative:
    >>> >> >>
    >>> >> >>
    http://windowssdk.msdn.microsoft.com/library/en-us/wpf_conceptual/html/ecb97ed4-e659-48a4-a1e0-893309569f2f.asp
    >>> >> >>
    >>> >> >> Please note that this sample is quite complicated in the sense
    >>> >> >> that
    >>> >> >> they
    >>> >> >> are
    >>> >> >> showing you how to create a color configuration UI in an
    >>> >> >> extensible
    >>> >> >> fashion.
    >>> >> >> You can create a simpler version of the same, using the ideas
    >>> >> >> presented
    >>> >> >> in
    >>> >> >> this article.
    >>> >> >>
    >>> >> >> Thanks,
    >>> >> >> -Unni
    >>> >> >> --
    >>> >> >> This posting is provided "AS IS" with no warranties, and confers
    >>> >> >> no
    >>> >> >> rights.
    >>> >> >> "Bela Istok" <bela_i@hotmail.com> wrote in message
    >>> >> >> news:C91CBACB-AF06-442C-97A3-3A905D252E47@microsoft.com...
    >>> >> >> > How I can databind 3 slider's to represent an collor in other
    >>> >> >> > control,
    >>> >> >> > below
    >>> >> >> > are my code.
    >>> >> >> >
    >>> >> >> >
    >>> >> >> > --
    >>> >> >> > Bela Istok
    >>> >> >> >
    >>> >> >> > <Grid
    >>> >> >> > xmlns="
    http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    >>> >> >> > xmlns:x="
    http://schemas.microsoft.com/winfx/2006/xaml"
    >>> >> >> > xmlns:mc="
    http://schemas.openxmlformats.org/markup-compatibility/2006"
    >>> >> >> > xmlns:d="
    http://schemas.microsoft.com/expression/interactivedesigner/2006"
    >>> >> >> > Background="#FFFFFFFF"
    >>> >> >> > x:Name="DocumentRoot"
    >>> >> >> > Width="480" Height="480">
    >>> >> >> > <Grid.Resources>
    >>> >> >> > </Grid.Resources>
    >>> >> >> >
    >>> >> >> > <Grid.Triggers>
    >>> >> >> > </Grid.Triggers>
    >>> >> >> >
    >>> >> >> > <Grid.ColumnDefinitions>
    >>> >> >> > <ColumnDefinition/>
    >>> >> >> > </Grid.ColumnDefinitions>
    >>> >> >> > <Grid.RowDefinitions>
    >>> >> >> > <RowDefinition/>
    >>> >> >> > </Grid.RowDefinitions>
    >>> >> >> > <DockPanel>
    >>> >> >> >
    >>> >> >> >
    >>> >> >> > <DockPanel Width="33.3">
    >>> >> >> > <TextBlock DockPanel.Dock="Top"
    >>> >> >> > Foreground="Red">Red</TextBlock>
    >>> >> >> > <TextBlock DockPanel.Dock="Bottom" Foreground="Red"
    >>> >> >> > Text="{Binding Value, ElementName=redS, Mode=Default}" />
    >>> >> >> > <Slider x:Name="redS" Orientation="Vertical"
    >>> >> >> > Maximum="255"
    >>> >> >> > SmallChange="1" />
    >>> >> >> > </DockPanel>
    >>> >> >> >
    >>> >> >> > <DockPanel Width="33.3">
    >>> >> >> > <TextBlock DockPanel.Dock="Top"
    >>> >> >> > Foreground="Green">Green</TextBlock>
    >>> >> >> > <TextBlock DockPanel.Dock="Bottom" Foreground="Green"
    >>> >> >> > Text="{Binding Value, ElementName=greenS, Mode=Default}" />
    >>> >> >> > <Slider x:Name="greenS" Orientation="Vertical"
    >>> >> >> > Maximum="255"
    >>> >> >> > SmallChange="1" />
    >>> >> >> > </DockPanel>
    >>> >> >> >
    >>> >> >> > <DockPanel Width="33.3">
    >>> >> >> > <TextBlock DockPanel.Dock="Top"
    >>> >> >> > Foreground="Blue">Blue</TextBlock>
    >>> >> >> > <TextBlock DockPanel.Dock="Bottom" Foreground="Blue"
    >>> >> >> > Text
    >>> >> >> > ="{Binding Value, ElementName=blueS, Mode=Default}"/>
    >>> >> >> > <Slider x:Name="blueS" Orientation="Vertical"
    >>> >> >> > Maximum="255"
    >>> >> >> > SmallChange="1" />
    >>> >> >> > </DockPanel>
    >>> >> >> >
    >>> >> >> >
    >>> >> >> > <TextBlock DockPanel.Dock="Left"
    >>> >> >> > Width="353.05" Background="#FF000000"/>
    >>> >> >> > </DockPanel>
    >>> >> >> > </Grid>
    >>> >> >>
    >>> >> >>
    >>> >> >>
    >>> >>
    >>> >>
    >>> >>
    >>>
    >>>
    >>>
    >
    >

    Tuesday, February 19, 2008 6:03 PM