C # Implementation Win10 UWP right click to surface in the click Position _c# Tutorial

Source: Internet
Author: User

This article mainly lets menuflyout appear in our right click position.

Our general use of Menuflyout is written at the front desk, written in the button, but maybe our menuflyout shows a different position than we'd like.

By using the background write Showat method, we can pass E. GetPosition get the mouse click position, you need to pass on the relative elements of the function, this element can generally use the elements we click to use, we can use the outermost grid, so we can get the mouse position, we can show our menuflyout in the click position.

We build a ListView and then bind the backstage, in our ListView to Right-click to show us the surfaced, asking us to surface where we clicked.

Menuflyout can be written in the background, of course, it can be written in the foreground.

We write this in the background, we can choose placement Display in our element position, but this is not our mouse click position, to show our mouse click position, actually very simple. We can get from E. GetPosition (sender as UIElement) get the mouse position and take this to menuflyout our surfacing shows in our mouse click position

<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>

Background Write

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 are want to show in the 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 Uiele ment));
}

The above is a small set to introduce the C # implementation Win10 UWP Right click on the click Position, hope for everyone to help, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.