简体   繁体   English

UWP:UserControl覆盖GridView项目单击

[英]UWP: UserControl override GridView item click

I have a UserControl inside of each GridView item. 我在每个GridView项目中都有一个UserControl It's like below. 就像下面。

<GridView Name="SymbolItemsGridView"
          Grid.Column="0"
          Background="#333333"
          SelectionMode="None"
          IsItemClickEnabled="True"
          ItemsSource="{x:Bind Items}"
          HorizontalAlignment="Stretch"
          Margin="15,5,10,15"
          ItemClick="SymbolGridView_ItemClick">
    <GridView.ItemTemplate>
        <DataTemplate x:DataType="data:SymbolItem">
            <local:SymbolControl Margin="10"/>
        </DataTemplate>
    </GridView.ItemTemplate>
</GridView>

The SymbolControl above is a UserControl , I changed its ContentPresenter style to round 上面的SymbolControl是一个UserControl ,我将其ContentPresenter样式更改为round

<ContentPresenter CornerRadius="40" 
                  Height="40"
                  Width="40"
                  Background="Cyan" 
                  x:Name="ContentPresenter" 
                  Content="{TemplateBinding Content}" 
                  Padding="0" />

So the only one button inside this UserControl is of round shape. 因此,此UserControl的唯一一个按钮是圆形的。

    <Button Name="SymbolButton" 
            Content="{x:Bind PhoneticSymbolItem.Text}" 
            Style="{StaticResource VowelSymbolButton}" />

在此处输入图片说明

My question is that the ItemClick="SymbolGridView_ItemClick" event handler only works when I click the corner of the GridView Item (the black part above). 我的问题是,仅当我单击GridView项的角(上面的黑色部分)时, ItemClick="SymbolGridView_ItemClick"事件处理程序才起作用。 If I click the round button, it doesn't work. 如果单击圆形按钮,则无法使用。

I know it's probably because the button is on top of the GridView item and clicking the button only triggers the button click event. 我知道这可能是因为该按钮位于GridView项的顶部,单击该按钮仅会触发该按钮单击事件。 But the media resource I want to set is in ItemsSource="{x:Bind Items}" of the GridView. 但是我要设置的媒体资源位于GridView的ItemsSource="{x:Bind Items}"中。 I don't know how to pass it to my UserControl and used by the button click event. 我不知道如何将其传递给UserControl并由按钮单击事件使用。

Or if there's a way to pop up the button click event to GridView item, it should work as well. 或者,如果有一种方法可以将按钮单击事件弹出到GridView项,那么它应该也可以正常工作。 I hope my question is clear, any ideas? 我希望我的问题很清楚,有什么想法吗?

对您的Round SymbolControl尝试IsHitTestVisible =“ False”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM