Binding ContextualGroups IsActive to MainWindow public property

4 posts, 0 answers
  1. Julian
    Julian avatar
    30 posts
    Member since:
    Sep 2010

    Posted 05 Aug 2014 Link to this post

    I have a MainWindow with various tabs. One of them is a Contextual Tab. I want to set the Contextual Tab's IsActive to the boolean IsFormAgentVisible value which is a public property in my MainWindow.xaml.cs

    I'm entirely new to WPF so I'm not sure a normal public property is the best way to go here. When I click on a ribbon button to launch a specific Window I set the IsFormAgentVisible to true. At this point I want to the contextualGroupFormAgents ContextualGroup below to be updated so that IsActive is now true. Hopefully this is a pretty simple task to perform. Thanks.


    Contextual Tab code from the MainWindow.xaml:
                 <telerik:RadRibbonView.ContextualGroups>
                    <telerik:RadRibbonContextualGroup x:Name="contextualGroupFormAgents" />
                </telerik:RadRibbonView.ContextualGroups>

                <telerik:RadRibbonTab Header="Form Agents" ContextualGroupName="contextualGroupFormAgents">
                    <telerik:RadRibbonGroup Header="Primary Details">
                        <telerik:RadRibbonDropDownButton Content="Change Primary Details" Click="ChangePrimaryDetailsDropDown_Click" />
                        <telerik:RadRibbonButton Content="Obsolete Forms"/>
                    </telerik:RadRibbonGroup>
                    <telerik:RadRibbonGroup Header="Process Status">
                        <telerik:RadRibbonDropDownButton Content="Update Process Status" Click="UpdateProcessStatusDropDown_Click" />
                    </telerik:RadRibbonGroup>
                    <telerik:RadRibbonGroup Header="Memos">
                        <telerik:RadRibbonButton Content="Add Memos"/>
                    </telerik:RadRibbonGroup>
                    <telerik:RadRibbonGroup Header="Submittal Details">
                        <telerik:RadRibbonDropDownButton Content="Change Submittals" Click="ChangeSubmittalsDropDown_Click"/>
                    </telerik:RadRibbonGroup>
                </telerik:RadRibbonTab>

    MainWindow.xaml.cs public property:
              public bool IsFormAgentVisible { get; set; }        
  2. Martin
    Admin
    Martin avatar
    1101 posts

    Posted 07 Aug 2014 Link to this post

    Hello Julian,

    Thank you for the code snippet.

    If you are not using the MVVM pattern in your application I recommend you instead of a property in the code-behind of the MainWindow to change directly the IsActive property of the contextual group using its x:Name.

    private void activateGroupBtn_Click(object sender, RoutedEventArgs e)
    {
        this.contextualGroupFormAgents.IsActive = true;
    }
    This way you won't need to create an additional property. 

    If you are using MVVM you can define the boolean IsFormAgentVisible property in your MainViewModel and bind it to the contextual group's IsActive property. Here is a simple example:

    public class ExampleViewModel : ViewModelBase
    {
        private bool isFormAgentVisible;
        public bool IsFormAgentVisible
        {
            get { return this.isFormAgentVisible; }
            set
            {
                this.isFormAgentVisible = value;
                OnPropertyChanged("IsFormAgentVisible");
            }
        }
        ...
    }

    <telerik:RadRibbonContextualGroup x:Name="contextualGroupFormAgents" IsActive="{Binding IsFormAgentVisible}" />

    As a side note, in order for the UI to listen for dynamic changes in its bound properties, those properties should implement the INotifyPropertyChanged interface.

    Please let me know if this helps.

    Regards,
    Martin
    Telerik
     
    Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
     
  3. UI for WPF is Visual Studio 2017 Ready
  4. Julian
    Julian avatar
    30 posts
    Member since:
    Sep 2010

    Posted 07 Aug 2014 in reply to Martin Link to this post

    Thanks Martin. We are not currently using MVVM but may convert the app to MVVM later (timing constraints are limiting us at this point) so thanks for given samples of both. I'll try setting IsActive in the RibbonButtonClick to launch my form. That should should work. I'll let you know. Thank you again
  5. Julian
    Julian avatar
    30 posts
    Member since:
    Sep 2010

    Posted 07 Aug 2014 Link to this post

    Martin that worked out great.

    Thanks!
Back to Top