Bind SelectedColor to Rectangle inside RadColorPicker

3 posts, 0 answers
  1. Luís
    Luís avatar
    1 posts
    Member since:
    Sep 2017

    Posted 19 Sep Link to this post

    Hello Sirs,

    I'm trying to show the selectedColor/selectedItem in a rectangle which is inside my RadColorPicker.

    <Style TargetType="telerik:RadColorPicker" 
               x:Name="colorPicker"
               BasedOn="{StaticResource StandardInputControlStyle}"
               >
            <Setter Property="Margin" Value="5,0,10,5"></Setter>
            
            <Setter Property="ContentTemplate">
                <!-- responsible for the button's design -->
                <Setter.Value>
                    <DataTemplate>
                        <TextBlock>
                            <Rectangle HorizontalAlignment="Center" 
                                 VerticalAlignment="Center"
                                 Width="108" 
                                 Height="23" 
                                 x:Name="Rectangle" 
                                 Fill="{Binding ElementName=colorPicker, Path=SelectedColor}">
                            </Rectangle>
                        </TextBlock>
                    </DataTemplate>
                </Setter.Value>
            </Setter>
        </Style>
  2. Vladimir Stoyanov
    Admin
    Vladimir Stoyanov avatar
    22 posts

    Posted 20 Sep Link to this post

    Hello Luis,

    In order to bind to the SelectedColor of the RadColorPicker you can use a RelativeSource binding and set the AncestorType to be RadColorPicker. You should also implement a ValueConverter in order to convert the color into a Brush.

    Please find a simple project attached which implements this behavior.

    I hope you find this helpful. Let me know if you have any more questions.

    Regards,
    Vladimir Stoyanov
    Progress Telerik
    Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
  3. Luis
    Luis avatar
    1 posts
    Member since:
    Sep 2017

    Posted 25 Sep in reply to Vladimir Stoyanov Link to this post

    I really appreciate your attention, Sir.

    That helped me a lot.
Back to Top