欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

C#實(shí)現(xiàn)win10 uwp 右擊浮出窗在點(diǎn)擊位置

 更新時(shí)間:2016年10月09日 11:35:56   作者:lindexi_gd  
本文主要讓MenuFlyout出現(xiàn)在我們右擊位置。我們建一個(gè)ListView,然后綁定后臺(tái),在我們ListView要右擊顯示我們的浮出,要求我們的浮出在我們點(diǎn)擊位置

本文主要讓MenuFlyout出現(xiàn)在我們右擊位置。

我們一般使用的MenuFlyout寫在前臺(tái),寫在Button里面,但是可能我們的MenuFlyout顯示的位置和我們想要的不一樣。

通過使用后臺(tái)寫ShowAt的方法,我們可以通過e.GetPosition獲得鼠標(biāo)點(diǎn)擊位置,需要對函數(shù)傳入相對的元素,這個(gè)元素一般可以用我們點(diǎn)擊使用的元素,也可以使用我們的最外層Grid,這樣我們就可以獲得了鼠標(biāo)位置,也就可以顯示我們的MenuFlyout在點(diǎn)擊位置。

我們建一個(gè)ListView,然后綁定后臺(tái),在我們ListView要右擊顯示我們的浮出,要求我們的浮出在我們點(diǎn)擊位置。

MenuFlyout可以在后臺(tái)寫,當(dāng)然寫在前臺(tái)也可以。

我們這寫在后臺(tái),我們可以選擇Placement 顯示在我們元素的位置,但這不是我們鼠標(biāo)點(diǎn)擊的位置,要顯示我們鼠標(biāo)點(diǎn)擊的位置,其實(shí)也很簡單。我們可以從e.GetPosition(sender as UIElement)獲得鼠標(biāo)位置,把這個(gè)給MenuFlyout我們的浮出顯示在我們鼠標(biāo)點(diǎn)擊位置

<ListView ItemsSource="{x:Bind View.Str}">
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Setter Property="HorizontalContentAlignment"
Value="Stretch" />
<Setter Property="VerticalContentAlignment" Value="Center"></Setter>
</Style>
</ListView.ItemContainerStyle>
<ListView.ItemTemplate>
<DataTemplate>
<Grid Background="#FFda2a5c" RightTapped="GridColection_OnRightTapped">
<TextBlock Text="{Binding}"></TextBlock>
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>

后臺(tái)寫

private void GridColection_OnRightTapped(object sender, RightTappedRoutedEventArgs e)
{
MenuFlyout myFlyout = new MenuFlyout();
MenuFlyoutItem firstItem = new MenuFlyoutItem { Text = "OneIt" };
MenuFlyoutItem secondItem = new MenuFlyoutItem { Text = "TwoIt" };
myFlyout.Items.Add(firstItem);
myFlyout.Items.Add(secondItem);
//if you only want to show in left or buttom 
//myFlyout.Placement = FlyoutPlacementMode.Left;
FrameworkElement senderElement = sender as FrameworkElement;
//the code can show the flyout in your mouse click 
myFlyout.ShowAt(sender as UIElement, e.GetPosition(sender as UIElement));
}

以上所述是小編給大家介紹的C#實(shí)現(xiàn)win10 uwp 右擊浮出窗在點(diǎn)擊位置,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!

相關(guān)文章

最新評論