【发布时间】:2015-08-20 20:00:23
【问题描述】:
我有一个非常常见的设计 MVVM 应用程序:MainWindow 有一个 ContentPresenter 定义如下:
<ContentPresenter Grid.Row="1" Grid.Column="1"
Content="{Binding Path=CurrentViewModel}">
</ContentPresenter>
它使用DataTemplate并且可以切换视图:
<DataTemplate DataType="{x:Type vm:PlateEntireViewModel}">
<v:PlateEntireView/>
</DataTemplate>
PlateEntireView 是一个以 PlateEntireViewModel 作为 DataContext 的用户控件。现在 - 我想在 PlateEntireViewModel 中有一个属性,它将在 MainWindow 内保存 PlateEntireView 的实际位置(左、上)。这可以实现吗?是否可以制作一些 DependencyProperty 并在 PlateEntireView 中使用它,例如:
<Grid ext:CustomProperties.ActualPositionX="{Binding Path=ActualPositionX, Mode=OneWayToSource}">
</Grid>
谁能告诉我这是否是正确的尝试方式 - 以及如何使用它?
【问题讨论】: