Multiple views using Microsoft.Windows.Controls.Ribbon
-
07-06-2021 - |
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?
Solution
You have a few options.
- Hook the
SelectionChanged
event and trade out your view's content. If you're using Prism, you could probably create aSelectorRegionAdapter
to do this for you. - You could bind to
Ribbon.SelectedValue
(settingSelectedValuePath
to sayLabel
) and provide aDataTrigger
which handles each of your tab's names. You could put an instance of each view model (assuming your
RibbonWindow
s data context has each of the view models you need) you care about in theRibbonTab.Tag
property, and adapt your view based onSelectedItem.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