0

我有一个包含项目列表的用户控件。

如果选择了一个项目,我想用一个面板和一些按钮来显示/替换视图,而不是什么。

当用户通过按下按钮或其他东西完成此视图时,我想再次返回到列表并继续该过程。

本质上,这是一个向导。

该怎么办?

抱歉,我忘了提到我正在使用 MVVM。

解决方案:

感谢大家的帮助。我的测试应用程序不工作,这促使我问 SO。

我的测试应用程序无法运行,因为我错过了 DataTemplate 中的 {x:type}。

简单地说:

我使用 {x:Type} 在资源中创建了不同的数据模板

我的视图模型:包含 IWizardPageViewModel 的复合集合。包含一个 currentPage 属性。包含 NextCommand/BackCommand 以更改 currentPage

我将 currentPage 属性绑定到控件,然后数据模板接管。

Because of the {x:Type} it wasn't working.

I don't know whether this is right or wrong, but it works and is mostly controlled by the viewmodel rather than triggers on the view.

4

3 回答 3

0

First thing that comes to my mind (and easiest) is to use Visibility property and bind it to some boolean flags in ViewModel that will indicate current UI state. Of course in this case you should apply a Converter to properly convert bool value to Visibility. There are dozens of examples of such kind of convertors.

But this is relevant only in for of small amount of such Controls. In case of really lots of UI elements that should be shown and replaced on a view it's better to use framework like Prism. From scratch it will be not so straightforward, but then you'll feel all power of flexibility.

In case you're not following MVVM culture (or you don't like having such backing properties) you can bind Visibility property of control A that should be shown to Booleaen property of element B which stands for show/hide logic. To make it clear:

<TextBlock x:Name="A" Visibility="{Binding IsChecked, ElementName=B, Converter={StaticResource boolToVisibilityConverter}}" Text="Some text."/> 
<ToggleButton x:Name="B" IsChecked="False"/>
于 2013-10-22T11:54:19.203 回答
0

考虑一个用户控件列表——向导的每一页都有一个。顶级用户控件(向导控件)将拥有此列表。对于导航,您可以;

于 2013-10-22T12:43:20.300 回答
0

您可以使用触发器和选择器根据用户操作更新视图 (DataTemplate)。让我知道您是否需要相同的代码片段。

于 2013-10-22T11:59:02.163 回答