C# 视图中xaml的切换部分(Caliburn.Micro)
我只想切换视图的一部分(即UserControl)xaml。 例如,我希望能够只更改第二个网格C# 视图中xaml的切换部分(Caliburn.Micro),c#,wpf,xaml,datatemplate,caliburn.micro,C#,Wpf,Xaml,Datatemplate,Caliburn.micro,我只想切换视图的一部分(即UserControl)xaml。 例如,我希望能够只更改第二个网格 <Grid> //main grid <Grid Name="1" Grid.Row="1"/> <Grid Name="2" Grid.Row="2"/> </Grid //主网格 只能加载一个视图。 了解视图分辨率的基本知识 基本上,您可以在视图中创建以下内容: <UserControl.Resources> <
<Grid> //main grid
<Grid Name="1" Grid.Row="1"/>
<Grid Name="2" Grid.Row="2"/>
</Grid
//主网格
只能加载一个视图。
了解视图分辨率的基本知识
基本上,您可以在视图中创建以下内容:
<UserControl.Resources>
<ControlTemplate x:Key="UsualMode">
<Grid>
...
</Grid>
</ControlTemplate>
</UserControl.Resources>
<Grid> //main grid
<Grid Name="1" Grid.Row="1"/>
<ContentControl x:Name="ChildViewModel" cal:View.Context="{Binding ContextBinding}" />
</Grid>
然后将根据ContextBinding
字符串解析您的视图(按照上面的CM约定)
因此,如果要更新字符串:
ContextBinding = "DetailedView";
然后,CM将更新UI,并尝试在当前VMs命名空间的子命名空间中查找名为DetailedView
的视图
如果你不想有一个子虚拟机,你实际上可以让CMs约定提前生效,并在当前虚拟机上应用上下文,但在这种情况下,你需要创建两个几乎相同的视图,除了你想“交换”的区域之外
我的首选方法是创建一个子VM来处理将交换视图的子区域,如我上面所示您希望能够在同一视图模型上切换视图吗?如果Caliburn Micro支持开箱即用,请查看View.Context
附加属性和CM文档。“我不能使用导体->只能加载一个视图。”只有一个视图,但此视图的内容是可切换的。
public class ParentViewModel
{
public SomeViewModel ChildViewModel { get; private set; }
public string ContextBinding { get; private set; } // make sure you implement INPC on these properties as is the usual
}
ContextBinding = "DetailedView";