Question

I have a WPF ribbon application using Microsoft.Windows.Controls.Ribbon. I can set the view through the Grid.Row tag:

    </ribbon:Ribbon>
    <Grid Grid.Row="1">
      <!-- View's content here -->
    </Grid>
  </Grid>
</ribbon:RibbonWindow>

Q: How can I change the view depending on the selected ribbon tab?

Was it helpful?

Solution

You have a few options.

  1. Hook the SelectionChanged event and trade out your view's content. If you're using Prism, you could probably create a SelectorRegionAdapter to do this for you.
  2. You could bind to Ribbon.SelectedValue (setting SelectedValuePath to say Label) and provide a DataTrigger which handles each of your tab's names.
  3. You could put an instance of each view model (assuming your RibbonWindows data context has each of the view models you need) you care about in the RibbonTab.Tag property, and adapt your view based on SelectedItem.Tag:

    <r:Ribbon x:Name="PART_Ribbon" ...>
        <r:RibbonTab Tag="{Binding HomeViewModel}" ... />
    </r:Ribbon>
    <Grid>
        <ContentControl Content="{Binding SelectedItem.Tag,
                                          ElementName=PART_Ribbon}" />
    </Grid>
    
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top