[Note that I asked the wrong question on the first blow to diagnose this - now fixed.]
I have a WPF application with one main window that inherits from Conductor.Collection.OneActive. It handles navigation requests and stores a cache in viewmodels to maintain state. This private collection is almost identical to the base. A collection of elements, but not for all view models, is IScreen.
Everything works fine, and the state persists when we move from one active element to another. However, there is an error with interaction triggers. When the active element is IScreen, triggers trigger extra time for each navigation, as if they were connected again each time; conventional triggers do not, only those from the interaction library. If the active element is not IScreen - just inherits from PropertyChangedBase - we do not see this problem, but we also lose the view state during navigation.
If you go to view four times, events will fire four times, five times, five, etc.
It looks like this question , but I can’t use its solution, since I don’t know what certain viewmodels are and cannot create public properties for them.
My main window class is as follows:
public sealed class MainWindowViewModel : Conductor<object>.Collection.OneActive, IHandle<NavigateToUriMessage>
{
public void Handle(NavigateToUriMessage message)
{
var ignoredUris = RibbonUri.GetItems().Where(t => t.SubTabs.Count > 0).Select(t => t.Uri);
Func<string, bool> isMatch = uri => uri == message.Uri;
if (isMatch(RibbonUri.BookkeepingBatchView.Uri))
GetAndActivateViewModel<BatchPanelViewModel>(message);
...
}
private T GetAndActivateViewModel<T>(NavigateToUriMessage message) where T : class
{
var vm = GetViewModel<T>(message.Uri);
ActivateItem(vm);
return (T) vm;
}
private object GetViewModel<T>(string uri) where T : class
{
if (viewModelCache.ContainsKey(uri))
return viewModelCache[uri];
var vm = viewModelFactory.Create<T>();
viewModelCache.Add(uri, vm);
return vm;
}
}
My MainWindow XAML is as follows:
<Window x:Class="Ui.Views.MainWindowView"
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"
d:DataContext="{d:DesignInstance Type=viewModels:MainWindowViewModel, IsDesignTimeCreatable=False}"
mc:Ignorable="d"
WindowState="Maximized" >
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="1"/>
<RowDefinition/>
<RowDefinition Height="1"/>
<RowDefinition Height="25"/>
</Grid.RowDefinitions>
<ContentControl x:Name="MainRibbon" Grid.Row="0" Margin="0" />
<Grid Background="#FFBBBBBB" Grid.Row="1" />
<ContentControl Grid.Row="2" x:Name="ActiveItem" Background="White" />
<Grid Grid.Row="3" Background="#FFBBBBBB"/>
<ContentControl x:Name="BottomStatusBar" Grid.Row="4"/>
</Grid>
</Window>
And the XAML in the view of the active element is as follows:
<DataGrid Focusable="True" FocusVisualStyle="{x:Null}" SelectionMode="Single" HeadersVisibility="None" IsReadOnly="True" GridLinesVisibility="None" AutoGenerateColumns="False" Background="Transparent" BorderThickness="0" Grid.Row="3" Grid.RowSpan="2">
<i:Interaction.Triggers>
<ei:KeyTrigger Key="Left" FiredOn="KeyUp" ActiveOnFocus="True" >
<cal:ActionMessage MethodName="TryCollapseSelectedItem"/>
</ei:KeyTrigger>
<ei:KeyTrigger Key="Right" FiredOn="KeyUp" ActiveOnFocus="True" >
<cal:ActionMessage MethodName="TryExpandSelectedItem"/>
</ei:KeyTrigger>
</i:Interaction.Triggers>
....