UIElement.ContextFlyout 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得或設定與此元素相關的飛出。
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。