我正在开发向导类型的应用程序,在其中维护向导
名为List<ViewmodelsForWizard>
的列表。
我使用相同的UserControl UCView
通过简单地调整存储在ViewModel
中的List<ViewmodelsForWizard>
值来呈现两个不同的页面。
问题在于,上一页的SelectionChangedCommand在下一页加载时被触发。 (两个页面都使用相同的UserControl UCView
和ViewModel
)
MainWindow
<Grid DataContext="{Binding currentWizard}">
<Grid.Resources>
<DataTemplate DataType="{x:Type viewmodel}">
<local:UCView DataContext="{Binding}"/>
</DataTemplate>
</Grid.Resources>
<ContentControl Content="{Binding}" />
</Grid>
我有以下ViewModel
:
//all other properties and commands
private ICommand selectionChangedCommand;
public ICommand SelectionChangedCommand
{
get
{
if (selectionChangedCommand == null)
selectionChangedCommand = new DelegateCommand(OnSelectionChanged());
return selectionChangedCommand;
}
set
{
selectionChangedCommand = value;
}
}
//all other properties and commands
选择已在UCView
<ComboBox ItemsSource="{Binding items}"
DisplayMemberPath="data"
SelectedValue="{Binding selected}">
<i:Interaction.Triggers>
<i:EventTrigger EventName="SelectionChanged">
<i:InvokeCommandAction Command="{Binding SelectionChangedCommand}" />
</i:EventTrigger>
</i:Interaction.Triggers>
</ComboBox>
任何帮助都会很棒。谢谢。