在Splitview中添加ListviewItem

时间:2015-08-08 07:21:55

标签: xaml windows-phone windows-10

我正在创建一个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>

1 个答案:

答案 0 :(得分:2)

根据我的理解,只要您按下包含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(buton或TextBlock)的内容时,方法“ListViewItem_Tapped”将触发。

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

度过美好的一天!

PS。按钮仍然像按钮一样“动作”,显示它自己的边框,视觉状态等。我不知道从头到尾如何禁用它。但您可以尝试禁用它或使用其他文本块吗? .DS