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

binding to Header in a menuitem

3 Answers 95 Views
ContextMenu
This is a migrated thread and some comments may be shown as answers.
Kenneth
Top achievements
Rank 2
Kenneth asked on 06 Dec 2013, 12:33 PM
Hi Telerik
In a usercontrol, I have this property in the code behind:

 

public string MyText
        {
            get {return "My text";}
            set {}
        }

 

In xaml, the usercontrol have the name: x:Name="This"

Could you somehow, please help me to get MyText into the header in the menuItem?- the following example, is not working for me: 

 

<telerik:RadToggleButton Tag="{Binding ElementName=This}" Content="Click me" IsChecked="{Binding IsOpen, ElementName=radContextMenu, Mode=TwoWay}">
 
            <telerik:RadContextMenu.ContextMenu >
                <telerik:RadContextMenu x:Name="radContextMenu" Placement="Bottom" IconColumnWidth="0" DataContext="{Binding RelativeSource={RelativeSource Self}, Path=PlacementTarget.Tag}">
                    <telerik:RadMenuItem Header="{Binding Path=MyText}" />
                </telerik:RadContextMenu>
            </telerik:RadContextMenu.ContextMenu>
 
        </telerik:RadToggleButton>

Thanks from Kenneth :o)

 

 

 

3 Answers, 1 is accepted

Sort by
0
Kenneth
Top achievements
Rank 2
answered on 10 Dec 2013, 07:23 PM
I hope someone can help me :-)
0
Rosen Vladimirov
Telerik team
answered on 11 Dec 2013, 12:32 PM
Hello Kenneth,

I've prepared a sample project to demonstrate how you can achieve your goal. Please find it attached and inform us in case you have any problems or concerns.

I would like to inform you that you are able to use RadContextMenu as a content of RadDropDownButton, so if you need this functionality, there's no need to use RadToggleButton. The code is shown below:
<telerik:RadDropDownButton x:Name="DropDownButton" Content="RadDropDownButton">
    <telerik:RadDropDownButton.DropDownContent>
        <telerik:RadContextMenu x:Name="radContextMenu2">
            <telerik:RadMenuItem Header="{Binding Path=DataContext.MyText, ElementName=DropDownButton}" />
        </telerik:RadContextMenu>
    </telerik:RadDropDownButton.DropDownContent>
</telerik:RadDropDownButton>

Hope this helps. Feel free to contact us in case you have any problems or concerns.

Regards,
Rosen Vladimirov
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
Kenneth
Top achievements
Rank 2
answered on 11 Dec 2013, 04:16 PM
Thank you so much for the two tips Rosen!

I ended up using raddropdown as you suggested:
<Window... x:Name="This"...>
<telerik:RadDropDownButton>
            <telerik:RadDropDownButton.DropDownContent>
                <telerik:RadContextMenu>
                    <telerik:RadMenuItem Header="{Binding MyText, ElementName=This}" />
                </telerik:RadContextMenu>
            </telerik:RadDropDownButton.DropDownContent>
        </telerik:RadDropDownButton>

Kind regards from Kenneth
Tags
ContextMenu
Asked by
Kenneth
Top achievements
Rank 2
Answers by
Kenneth
Top achievements
Rank 2
Rosen Vladimirov
Telerik team
Share this question
or