2017-12-27 125 views
0

我有一個GridView,並且在此Gridview中有幾個包含其他元素的Grid。如果我點擊一個GridView元素(一個Grid),我想打開這個元素的細節,但Grid和GridView似乎不支持設置點擊方法。單擊某個元素時還可以調用方法嗎?如何檢測GridView中的單擊

回答

0

您可以添加一個不可見的矩形或其他元素來註冊OnMouseOver事件或單擊等。

1

但電網和GridView不似乎支持設置點擊方法

使用Tapped事件。

+0

它看起來像它的工作,但只有當我按像一個文本塊的網格的可見部分,但不是在t他看不見的部分。我怎樣才能讓它在那裏工作呢? – CodeSharpMarvin

+0

@CodeSharpMarvin你可以分享你迄今爲止的代碼嗎? –

0

您的每一個Grid的應該訂閱3個事件,並有透明背景:

<Grid Background="Transparent" PointerPressed="Grid_OnPointerPressed" PointerReleased="Grid_OnPointerReleased" PointerExited="Grid_OnPointerExited"> 

在代碼中,你可以模擬這樣的單擊事件:

private bool _isPressed; 

    private void Grid_OnPointerPressed(object sender, PointerRoutedEventArgs e) 
    { 
     _isPressed = true; 
    } 

    private void Grid_OnPointerReleased(object sender, PointerRoutedEventArgs e) 
    { 
     if (_isPressed) 
     { 
      //your logic on click event 
     } 

     _isPressed = false; 
    } 

    private void Grid_OnPointerExited(object sender, PointerRoutedEventArgs e) 
    { 
     _isPressed = false; 
    } 

或者最簡單的方法是來包裝你Grid分成Button