0

我正在实施 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 属性。

4

1 回答 1

0

FiltersViewSource 应该是某种类型的视图模型中的属性,例如“Foo”。在这种情况下,单选按钮将获得 Foo 类型的数据上下文。所以属性“FilterChangedCommand”应该在 Foo 类中。

于 2013-06-05T03:42:06.297 回答