在 Splitview 中添加 ListviewItem

Adding ListviewItem in Splitview

我正在创建一个 Windows 10 通用应用程序并且我已成功创建 shell.xaml 但我不想使用 radioButton 而不是我使用了按钮和 TextBlock。 我想知道如何通过 listView Item 使 TextBlock 和 Button 成为一个可单击的实体。

 <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
        <SplitView x:Name="mySplitView" DisplayMode="CompactInline"  IsPaneOpen="False" 
                CompactPaneLength="50" OpenPaneLength="150" Content="{Binding}">
            <SplitView.Pane>
                <StackPanel Background="{ThemeResource SystemControlBackgroundAccentBrush}">
                    <Button x:Name="HamburgerButton" FontFamily="Segoe MDL2 Assets" Content="&#xE700;"
                     Width="50" Height="50" Background="Transparent" Foreground="White"  Click="HamburgerButton_Click" />
                    <StackPanel Orientation="Horizontal">
                        <Button FontFamily="Segoe MDL2 Assets" Content="&#59724;"
                     Width="50" Height="50" Background="Transparent" Foreground="White">
                        <TextBlock Foreground="White" FontSize="10" VerticalAlignment="Center" />
                    </StackPanel>

据我了解,只要您按下包含 Button 和 TextBlock 的 StackPanel 中的某处,您就希望触发事件。

一种解决方案是将 Button 和 TextBlock 简单地放在 ListView 项中。

像这样(我将 SplitView.Pane 的所有 xaml 包括在内,以使其更清楚一点):

<SplitView.Pane>
    <StackPanel Background="{ThemeResource SystemControlBackgroundAccentBrush}">
        <Button x:Name="HamburgerButton" FontFamily="Segoe MDL2 Assets" Content="&#xE700;" Width="50" Height="50" Background="Transparent" Foreground="White"  Click="HamburgerButton_Click" />
        <ListView>
            <ListView.Items>
                <ListViewItem Padding="0" Tapped="ListViewItem_Tapped">
                    <StackPanel Orientation="Horizontal" VerticalAlignment="Top" Height="50">
                        <Button FontFamily="Segoe MDL2 Assets" Content="&#59724;" Width="50" Height="50" Background="Transparent" Foreground="White" />
                        <TextBlock Foreground="White" FontSize="10" Text="Wop wop!" VerticalAlignment="Center" />
                    </StackPanel>
                </ListViewItem>
            </ListView.Items>
        </ListView>
    </StackPanel>
</SplitView.Pane>

在此示例中,当窗格关闭时仅显示“%”,当窗格打开时仅显示“%”和文本 "Wop wop!"。每当按下此 ListViewItem(按钮或 TextBlock)的内容时,方法 "ListViewItem_Tapped" 就会触发。

如果我以任何方式误解了您的问题,或者您需要有关我的回答的更多信息,请告诉我。

祝你有美好的一天!

PS。该按钮仍然 "acts" 像一个按钮,通过显示它自己的边框、视觉状态等。我不知道如何禁用它。但是您也许可以尝试禁用它或改用另一个文本块? .DS