This is a migrated thread and some comments may be shown as answers.

Bind SelectedColor to Rectangle inside RadColorPicker

2 Answers 187 Views
ColorPicker
This is a migrated thread and some comments may be shown as answers.
Luís
Top achievements
Rank 1
Luís asked on 19 Sep 2017, 06:16 PM
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 Answers, 1 is accepted

Sort by
0
Vladimir Stoyanov
Telerik team
answered on 20 Sep 2017, 01:02 PM
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.
0
Luis
Top achievements
Rank 1
answered on 25 Sep 2017, 04:22 PM
I really appreciate your attention, Sir.

That helped me a lot.
Tags
ColorPicker
Asked by
Luís
Top achievements
Rank 1
Answers by
Vladimir Stoyanov
Telerik team
Luis
Top achievements
Rank 1
Share this question
or