語言

UIElement.ContextFlyout 屬性

定義

取得或設定與此元素相關的飛出。

public:
 property FlyoutBase ^ ContextFlyout { FlyoutBase ^ get(); void set(FlyoutBase ^ value); };
FlyoutBase ContextFlyout();

void ContextFlyout(FlyoutBase value);
public FlyoutBase ContextFlyout { get; set; }
var flyoutBase = uIElement.contextFlyout;
uIElement.contextFlyout = flyoutBase;
Public Property ContextFlyout As FlyoutBase

屬性值

與此元素相關的飛出(若有);否則,。 null 預設值為 null。

範例

這個範例展示了如何在矩形上附加一個包含紅色和綠色選項的右鍵選單。 當使用者右鍵點擊或執行等效動作時,選單會顯示出來。

一個右鍵選單顯示紅色和綠色選項
<Page
    ...>
    <Page.Resources>
        <MenuFlyout x:Key="colorMenuFlyout">
            <MenuFlyoutItem Text="Red" Tag="red" Click="MenuFlyoutItem_Click"/>
            <MenuFlyoutItem Text="Green" Tag="green" Click="MenuFlyoutItem_Click"/>
        </MenuFlyout>
    </Page.Resources>

    <Grid>
        <Rectangle Width="100" Height="100" Fill="Yellow"
                   ContextFlyout="{StaticResource colorMenuFlyout}">
        </Rectangle>
    </Grid>
</Page>
private void MenuFlyoutItem_Click(object sender, RoutedEventArgs e)
{
    var colorMenuFlyout = Resources["colorMenuFlyout"] as MenuFlyout;
    var item = sender as MenuFlyoutItem;
    var target = colorMenuFlyout.Target;
    if (string.Equals(item.Tag.ToString(), "red"))
    {
        ((Rectangle)target).Fill = new SolidColorBrush(Windows.UI.Colors.Red);
    }
    else if (string.Equals(item.Tag.ToString(), "green"))
    {
        ((Rectangle)target).Fill = new SolidColorBrush(Windows.UI.Colors.Green);
    }
}

備註

一個情境選單會附加在單一元素上,並顯示次要指令。 透過右鍵點擊或等效動作(如用手指長按)來觸發。

當你設定該屬性時 ContextFlyout ,右鍵選單會自動顯示並隱藏, ContextRequested 事件會被標記為已處理。 你應該只處理 ContextRequested , ContextCanceled 如果你沒有設定 ContextFlyout。

適用於