-
|
my MainView.xaml: <Window>
<ListBox ItemsSource="{Binding PageTypes}" SelectedItem="{Binding SelectedPage}" />
<ContentControl s:View.Model="{Binding ActiveItem}" />
</Window>MainViewModel.cs: public class MainViewModel : Conductor<IScreen>.Collection.OneActive
{
public ObservableCollection<Type> PageTypes { get; } =
[
// some Screen types:
typeof(FooViewModel),
typeof(BarViewModel),
typeof(XXXViewModel),
];
public Type SelectedPage
{
get => field;
set
{
if (field==value)
return;
field = value;
ActiveItem = GetOrCreatePage(value);
}
}
IScreen GetOrCreatePage(Type type)
{
if (type is null)
return null;
var page = Items.FirstOrDefault(x => x.GetType() == type);
if (page == null)
{
page = (IScreen)_container.Get(type);
Items.Add(page);
}
return page;
}
}So I click item in ListBox to switch different views, why switch back to already created view before, it always occur |
Beta Was this translation helpful? Give feedback.
Answered by
ahdung
Jan 30, 2026
Replies: 1 comment
-
|
I think i know, when switch ActiveItem, old view(a |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
ahdung
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I think i know, when switch ActiveItem, old view(a
UserControl) removed from VisualTree, so it occurUnloaded, when re-show it, it needLoaded, it is WPF thing not related stylet.