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

Binding ContextualGroups IsActive to MainWindow public property

3 Answers 114 Views
RibbonView and RibbonWindow
This is a migrated thread and some comments may be shown as answers.
Julian
Top achievements
Rank 1
Julian asked on 05 Aug 2014, 03:21 PM
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; }        

3 Answers, 1 is accepted

Sort by
0
Martin Ivanov
Telerik team
answered on 07 Aug 2014, 02:37 PM
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.
 
0
Julian
Top achievements
Rank 1
answered on 07 Aug 2014, 02:41 PM
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
0
Julian
Top achievements
Rank 1
answered on 07 Aug 2014, 07:29 PM
Martin that worked out great.

Thanks!
Tags
RibbonView and RibbonWindow
Asked by
Julian
Top achievements
Rank 1
Answers by
Martin Ivanov
Telerik team
Julian
Top achievements
Rank 1
Share this question
or