How can I bind a colorpicker inside a ContextMenu to a label?

641 Views Asked by At

I have a custom context menu on my window like so, which contains two color pickers--one for foreground and one for background:

<ContextMenu>
    <ContextMenu.Template>
        <ControlTemplate>
            <Border BorderBrush="Black" BorderThickness="1" Background="White">
                <UniformGrid Rows="2">
                    <Border BorderBrush="Black" BorderThickness="0,0,0,1">
                        <DockPanel Margin="5">
                            <Label Content="Background Color" Margin="0,0,10,0" DockPanel.Dock="Left"/>
                            <xctk:ColorPicker DisplayColorAndName="True" ColorMode="ColorCanvas" SelectedColor="Gray" DockPanel.Dock="Right"/>
                        </DockPanel>
                    </Border>
                    <DockPanel Margin="5">
                        <Label Content="Foreground Color" Margin="0,0,10,0" DockPanel.Dock="Left"/>
                        <xctk:ColorPicker Name="cpForegroundColor" DisplayColorAndName="True" ColorMode="ColorCanvas" SelectedColor="White" DockPanel.Dock="Right"/>
                    </DockPanel>
                </UniformGrid>
            </Border>
        </ControlTemplate>
    </ContextMenu.Template>
</ContextMenu>

How exactly could I bind the colorpicker's SelectedColor to a label I have inside the window?

I've attempted using ElementName but I guess this won't work due to differing namescopes. From what I've read it may not be a good idea to bind to things inside a control template as well.

Any suggestions on how (or a better way) to do this would be greatly appreciated--thanks!

0

There are 0 best solutions below