WinUI3 彈出式視窗 Popup

在 WinUI3 中要建立彈出式視窗,可以使用 Popup 達成,下面是一個簡單的示範:
    
<Popup x:Name="MyPopup">
    <Border BorderBrush="{StaticResource ApplicationForegroundThemeBrush}"
            Background="{StaticResource ApplicationPageBackgroundThemeBrush}"
            Padding="24"
            CornerRadius="4"
            >
        <StackPanel>
            <TextBlock Text="是否繼續" Margin="0,0,0,12" />
            <Button Content="確認" Click="myButton_Click2" />
        </StackPanel>
    </Border>
</Popup>

<Button Click="myButton_Click">按鈕</Button>
    

    
private void myButton_Click(object sender, RoutedEventArgs e)
{
    MyPopup.IsOpen = true;
}
private void myButton_Click2(object sender, RoutedEventArgs e)
{
    MyPopup.IsOpen = false;
}
    

按下按鈕後會讓 MyPopup 顯示,按下彈出式視窗的按鈕後會讓彈出式視窗消失。

留言