I have a ComboBox in an application Ribbon Menu, where the selected item binds to a theme of the application UI as follows:
Theme binding in MainWindow.xaml
Theme="{Binding SelectedItem.Tag, ElementName=_themeCombo}"
And the ComboBox
<ComboBox x:Name="_themeCombo" SelectedIndex="0" Width="200">
<ComboBoxItem Content="Generic" />
<ComboBoxItem Content="Aero">
<ComboBoxItem.Tag>
<xcad:AeroTheme />
</ComboBoxItem.Tag>
</ComboBoxItem>
</ComboBox>
The theme selection was working well, however, as the MainWindow.xaml is getting very long, I have moved my Menu Ribbon (and therefore the combobox) into a separate UserControl file named "Ribbon.xaml" and referenced it in as follows:
<local:Ribbon x:Name="RibbonWin" Grid.Row="0" />
This however, has broken the binding link for my theme selection. The Ribbon.xaml is in the same namespace as the mainwindow.xaml.
How do I provide a relative path to the ribbon ComboBox named “_themeCombo”?
I have tried placing the full address of the ComboBox in (inc class name of Ribbon) as follows, but this did not work:
Theme="{Binding SelectedItem.Tag, ElementName=DrainageDesign.View.Ribbon._themeCombo}"
You can add a dependency property to your
RibbonUserControland use it to transfer the value. Note you can use a more specific type thanobjectfor your actual ThemeThen bind the selected theme to the property
And use the transferred value inside the Ribbon. I assume you give your Ribbon UserControl an internal name of
_selffor this example. You can actually use any technique of your choice to access the property within your control.