I have a ribbon backstage which uses data binding to to populate the properties of its backstage items. My view currently looks as follows:
<actiproControls:Backstage x:Class="PrismApplicationPrototype.Modules.Backstage.BackstageView"
Name="Backstage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:actiproControls="clr-namespace:ActiproSoftware.Windows.Controls.Ribbon.Controls;assembly=ActiproSoftware.Ribbon.Wpf"
xmlns:my="clr-namespace:PrismApplicationPrototype.Modules.Backstage"
mc:Ignorable="d"
d:DataContext="{d:DesignInstance Type=my:BackstageViewModel}"
d:DesignHeight="300" d:DesignWidth="300"
>
<actiproControls:BackstageTab Header="{Binding Test}"/>
<actiproControls:Button Label="{Binding Test}"
Command="{Binding CloseApplicationCommand}"
KeyTipAccessText="X" />
</actiproControls:Backstage>
And the corresponding view model:
public class BackstageViewModel
{
private ICommand closeApplicationCommand;
public ICommand CloseApplicationCommand
{
get { return this.closeApplicationCommand ?? (this.closeApplicationCommand = new DelegateCommand(CloseApplication)); }
}
private void CloseApplication()
{
System.Windows.Application.Current.Shutdown();
}
public string Test {
get { return "Test"; }
}
}
Now, as soon as I click on the File button in the ribbon, which will show the Backstage, the Backstage's DataContext is changed and set to null. You can see this when subscribing the the Backstage's DataContextChanged event. Hence, in the running application the Backstage items have no labels or commands associated.
To test whether my bindings are OK I wrapped the Backstage into a Group inside of a Ribbon Tab. When doing this, the DataContext is not changed and the bindings work as expected. Of course this is not the proper place to put a Backstage...
// DataContext of the Backstage gets set to null. Bindings break.
//ribbon.ApplicationMenu = backstage;
// DataContext is kept. Bindings work.
var tab = new Tab {Label = "Tab hosting Backstage"};
var tabGroup = new Group();
tabGroup.Items.Add(backstage);
tab.Items.Add(tabGroup);
ribbon.Tabs.Add(tab);
[Modified 12 years ago]