Contextual Tab Binding to IsActive

2 posts, 1 answers
  1. Erich
    Erich avatar
    1 posts
    Member since:
    Aug 2013

    Posted 29 Aug 2013 Link to this post

    I am trying to bind a contextual group to the IsActive property using a custom property of a UserControl. The contextual tab should only be shown after the user has selected a port from a dropdown list. I have tried each of the following with no success, but hopefully it gives you an idea of what I'm trying to do.

    <telerik:RadRibbonView.ContextualGroups>
    <telerik:RadRibbonContextualGroup x:Name=
    "xCOM" IsActive="{Binding RelativeSource={RelativeSource Self}, Path=IsPortSelected}"/>
    <telerik:RadRibbonContextualGroup x:Name=
    "xCOM" IsActive="{Binding ElementName=_this, Path=IsPortSelected}"/>
    <telerik:RadRibbonContextualGroup x:Name=
    "xCOM" IsActive="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:MyRibbon}}, Path=IsPortSelected}"/>
    <telerik:RadRibbonContextualGroup x:Name=
    "xCOM" IsActive="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}, Path=IsPortSelected}"/>
    </telerik:RadRibbonView.ContextualGroups>

    Where IsPortSelected is the property in MyRibbon:

    string _port = "";
    public string Port
    {
        get { return _port; }
        set
        {
            if (_port == value)
            {
                return;
            }
            _port = value;
        }
    }
     
    public bool IsPortSelected
    {
        get
        {
            if (String.IsNullOrEmpty(_port))
            {
                return false;
            } else if (_port.Equals("Port")) {
                return false;
            }
            return true;
        }
        set { }
    }

    Is there something wrong with my binding statement? Or do I need to do something else in the code behind, such as implementing a PropertyChangedEventHandler (which I have tried with no success as well)?
  2. Answer
    Pavel R. Pavlov
    Admin
    Pavel R. Pavlov avatar
    1183 posts

    Posted 03 Sep 2013 Link to this post

    Hi Erich,

    You are on the right way to achieve your requirement. However, I think that you need to try to bind to your custom property like this:

    <telerik:RadRibbonContextualGroup x:Name="CG" IsActive="{Binding RelativeSource={RelativeSource AncestorType=local:MyRibbon}, Path=IsPortSelected}" />
    I achieved your requirement in the attached project. Please take a look at it and let me know if you need any further assistance.

    Regards,
    Pavel R. Pavlov
    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 >>
  3. UI for WPF is Visual Studio 2017 Ready
Back to Top