【问题标题】:Windows Store Apps: Grid View Group Header Button command not firing?Windows 应用商店应用程序:网格视图组标题按钮命令未触发?
【发布时间】:2013-04-30 15:54:26
【问题描述】:

我有一个带有以下组样式标题模板的网格视图:

<GroupStyle.HeaderTemplate>
                        <DataTemplate>
                            <Grid Margin="1,0,0,6">
                                <Button
                                    AutomationProperties.Name="Group Title"
                                    Command="{Binding GroupCommand}"
                                    Style="{StaticResource TextPrimaryButtonStyle}"
                                    >
                                    <StackPanel Orientation="Horizontal">
                                        <TextBlock Text="{Binding Key}" Margin="3,-7,10,10" Style="{StaticResource GroupHeaderTextStyle}" />
                                        <TextBlock Text="{StaticResource ChevronGlyph}" FontFamily="Segoe UI Symbol" Margin="0,-7,0,10" Style="{StaticResource GroupHeaderTextStyle}"/>
                                    </StackPanel>
                                </Button>
                            </Grid>
                        </DataTemplate>
                    </GroupStyle.HeaderTemplate>

问题是当我点击按钮时,GroupCommand 没有执行。

这可能是什么问题?

【问题讨论】:

  • 尝试网格的点击事件。

标签: windows-8 windows-store-apps winrt-xaml


【解决方案1】:

你应该试试这个方法:

private void Button_Tapped_1(object sender, TappedRoutedEventArgs e)
        {
            SampleDataItem item = new SampleDataItem("test", "test!", "subtitle", "", "", "", null);
            SampleDataSource.AddItemToFirstGroup(item);
        }

        private void Button_Tapped_2(object sender, TappedRoutedEventArgs e)
        {
            SampleDataGroup group = new SampleDataGroup("test", "testGroup", "subtitle", "", "");
            group.Items.Add(new SampleDataItem("test", "test!", "subtitle", "", "", "", null));
            SampleDataSource.AddGroup(group);
        }

【讨论】:

  • 感谢您的回答,但我想将按钮绑定到 ViewModel 中的 ICommand。请检查我的答案
【解决方案2】:

我从这里得到的 WinRT (Win 8) Store App XAML Bindings RelativeSourceMode FindAncestor missing?

我想将我的按钮绑定到我的 ViewModel 中的 ICommand,所以我这样做了:

 <GroupStyle.HeaderTemplate>
                            <DataTemplate>
                                <Grid Margin="1,0,0,6">
                                    <Button
                                        AutomationProperties.Name="Group Title"
                                        Command="{Binding ElementName=myParentGridView, Path=DataContext.GroupCommand}"
                                        Style="{StaticResource TextPrimaryButtonStyle}"
                                        >
                                        <StackPanel Orientation="Horizontal">
                                            <TextBlock Text="{Binding Key}" Margin="3,-7,10,10" Style="{StaticResource GroupHeaderTextStyle}" />
                                            <TextBlock Text="{StaticResource ChevronGlyph}" FontFamily="Segoe UI Symbol" Margin="0,-7,0,10" Style="{StaticResource GroupHeaderTextStyle}"/>
                                        </StackPanel>
                                    </Button>
                                </Grid>
                            </DataTemplate>
                        </GroupStyle.HeaderTemplate>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-30
    • 1970-01-01
    • 2015-12-12
    • 1970-01-01
    • 2023-03-31
    相关资源
    最近更新 更多