2015-08-08 63 views
2

我正在創建一個Windows 10通用應用程序,並且我已經成功創建了shell.xaml,但我不想使用radioButton而不是使用按鈕和TextBlock。 我想知道如何使TextBlock和按鈕通過listView項目單一可點擊的實體。在Splitview中添加ListviewItem

<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

看起來好像您的xaml缺少一些要完成的信息。另一個問:你說你不想使用radioButton,然後你問如何讓TextBlock和radioButton成爲一個clibale實體。它應該只是第二次提到radioButton的按鈕? – ILOABN

+0

@FabianMiiro道歉我的意思是按鈕和文本塊。我想要一個textblovk和按鈕一個單一的可點擊的實體使用列表視圖 – shriyanshk

回答

2

從我所瞭解的情況來看,只要按下包含Button和TextBlock的StackPanel中的某個位置,就會觸發事件。

一個解決方案是簡單地把你的Button和TextBlock放在一個ListView項中。

喜歡這張(I包括所有XAML爲SplitView.Pane到使它有點更清楚):當窗格關閉

<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

+0

那麼解決方案是完美的只剩下的東西是從按鈕刪除邊框。我讀了一些文章,似乎有解決方法,但x:靜態顯示不可用在我的情況下 http://stackoverflow.com/questions/995757/how-do-you-completely-remove-the-button-border-在-WPF – shriyanshk