我喜欢 Catel 框架。现代 UI 看起来很不错。但是我在尝试使它们一起工作时遇到了问题。
我在 mui 项目中Home
添加了两个 catels 用户控件。Second
问题是当从执行Home
到Second
执行的转换HomeViewModel
已经创建了 3 次。
这种行为是由下一个代码引起的TransitioningContentControl
private void StartTransition(object oldContent, object newContent)
{
// both presenters must be available, otherwise a transition is useless.
if (CurrentContentPresentationSite != null && PreviousContentPresentationSite != null) {
CurrentContentPresentationSite.Content = newContent;
PreviousContentPresentationSite.Content = oldContent;
// and start a new transition
if (!IsTransitioning || RestartTransitionOnContentChange) {
IsTransitioning = true;
VisualStateManager.GoToState(this, NormalState, false);
VisualStateManager.GoToState(this, Transition, true);
}
}
}
如果我评论一些行:
private void StartTransition(object oldContent, object newContent)
{
// both presenters must be available, otherwise a transition is useless.
if (CurrentContentPresentationSite != null && PreviousContentPresentationSite != null) {
CurrentContentPresentationSite.Content = newContent;
//PreviousContentPresentationSite.Content = oldContent;
// and start a new transition
if (!IsTransitioning || RestartTransitionOnContentChange) {
IsTransitioning = true;
//VisualStateManager.GoToState(this, NormalState, false);
//VisualStateManager.GoToState(this, Transition, true);
}
}
}
在这种情况下,相同的转换会导致创建HomeViewModel
1 次,但我不想在从控件HomeViewModel
执行导航时创建。Home
我怎样才能做到这一点?