binding to Header in a menuitem

4 posts, 0 answers
  1. Kenneth
    Kenneth avatar
    27 posts
    Member since:
    Nov 2010

    Posted 06 Dec 2013 Link to this post

    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)

     

     

     

  2. Kenneth
    Kenneth avatar
    27 posts
    Member since:
    Nov 2010

    Posted 10 Dec 2013 Link to this post

    I hope someone can help me :-)
  3. UI for WPF is Visual Studio 2017 Ready
  4. Rosen Vladimirov
    Admin
    Rosen Vladimirov avatar
    640 posts

    Posted 11 Dec 2013 Link to this post

    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 >>
  5. Kenneth
    Kenneth avatar
    27 posts
    Member since:
    Nov 2010

    Posted 11 Dec 2013 Link to this post

    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
Back to Top