【问题标题】:Adding ListviewItem in Splitview在拆分视图中添加 ListviewItem
【发布时间】:2015-10-31 15:58:41
【问题描述】:

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

【问题讨论】:

  • 您的 xaml 似乎缺少一些完整的信息。还有另一个问题:您说您不想使用 radioButton,然后您问如何使 TextBlock 和 radioButton 成为 clibale 实体。第二次提到radioButton应该只是按钮吗?
  • @FabianMiiro 道歉我的意思是按钮和文本块。我想要一个 textblovk 并使用 listview 按钮一个可点击的实体

标签: xaml windows-phone windows-10


【解决方案1】:

据我了解,当您按下包含 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。通过显示它自己的边框、视觉状态等,按钮仍然像一个按钮一样“行动”。我不知道如何禁用它。但是您也许可以尝试禁用它或改用另一个文本块? .DS

【讨论】:

  • 这个解决方案是完美的,唯一的事情就是从按钮上移除边框。我阅读了一些文章,似乎有解决方法,但 x:static 在我的情况下显示不可用 stackoverflow.com/questions/995757/…
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-02-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-05-10
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多