我正在实施 Windows 8 应用程序的搜索合同(结果页面)。我设计了一切来遵循 MVVM。有了这个,我正在尝试将命令连接到 Windows 8 搜索合同模板中提供的“filtersItemsControl”。
<ItemsControl
x:Name="filtersItemsControl"
Canvas.ZIndex="1"
ItemsSource="{Binding Source={StaticResource filtersViewSource}}"
Visibility="{Binding ShowFilters, Converter={StaticResource BooleanToVisibilityConverter}}"
Margin="120,-3,120,30">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<RadioButton
GroupName="Filters"
IsChecked="{Binding Active, Mode=TwoWay}"
common:CheckedCommandBehavior.Command="{Binding RelativeSource={RelativeSource Self}, Path=FilterChangedCommand}"
Style="{StaticResource TextRadioButtonStyle}">
<TextBlock Text="{Binding Description}" Margin="3,-7,3,10" Style="{StaticResource GroupHeaderTextStyle}" />
</RadioButton>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
上面的代码是我尝试连接到 ViewModel 的属性“FilterChangedCommand”。ViewModel 还包含 ItemsControl 绑定到的属性列表(filtersViewSource)。我认为我的问题是我试图将 RadioButton 的命令绑定到 filtersViewSource (显然不存在)与 ViewModel 的属性。
因此,我认为这里的问题基本上是,我可以在上面的 RadioButton 上使用什么绑定表达式,以便它引用 ViewModel 属性。