如何在.xaml中制作一个简单的ContentDialog?
How to make a simple ContentDialog in .xaml?
创建 ContentDialog 需要什么?
我基本上有一个按钮。当我点击该按钮时,ContentDialog 打开。 ContentDialog 应包括 "this is an example" 之类的文本和 2 个按钮。 <ConTentDialog></ContentDialog>
看起来像什么?示例:
<Page
x:Class="PDFViewerSDK_Win10.PDFReaderPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:PDFViewerSDK_Win10"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" SizeChanged="OnSizeChanged">
<ContentDialog x:Name="test" PrimaryButtonText="Ok" SecondaryButtonText="Cancel" Style="{StaticResource AppBarButtonStyle}" Tapped="OnOptionItemTapped" >
<Image Source="Assets/images/icon_menu.png"/>
</ContentDialog>
</Page>
可以在代码隐藏中轻松创建内容对话框。然后,您可以在您提到的按钮的单击事件中使用该 C# 代码 运行。
你的另一个选择是在 XAML 上创建一个内容对话框,因为你已经在你的原始问题中发布了,这样当点击按钮时,你只需参考代码隐藏中的内容对话框并调用 ShowAsync()
方法。
我可以在此回复中编写示例代码,但为了将来这个问题与访问者相关,我鼓励您参考 Microsoft's documentation,它将得到更好的维护。我已经看过了,里面有具体的例子,对你有很大的帮助。
编辑:
发布示例代码作为参考。
MainPage.XAML
:
<Grid>
<Button
HorizontalAlignment="Center"
VerticalAlignment="Center"
Height="100" Width="250"
Content="Show Content"
FontSize="30px"
x:Name="ContentBtn"
Click="ContentBtn_Click"/>
<ContentDialog x:Name="ContentDialog"
Title="This is an example"
PrimaryButtonText="Ok"
CloseButtonText="Cancel"
DefaultButton="Primary">
</ContentDialog>
</Grid>
MainPage.XAML.cs
:
private async void ContentBtn_Click(object sender, RoutedEventArgs e) {
await ContentDialog.ShowAsync();
}
创建 ContentDialog 需要什么?
我基本上有一个按钮。当我点击该按钮时,ContentDialog 打开。 ContentDialog 应包括 "this is an example" 之类的文本和 2 个按钮。 <ConTentDialog></ContentDialog>
看起来像什么?示例:
<Page
x:Class="PDFViewerSDK_Win10.PDFReaderPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:PDFViewerSDK_Win10"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" SizeChanged="OnSizeChanged">
<ContentDialog x:Name="test" PrimaryButtonText="Ok" SecondaryButtonText="Cancel" Style="{StaticResource AppBarButtonStyle}" Tapped="OnOptionItemTapped" >
<Image Source="Assets/images/icon_menu.png"/>
</ContentDialog>
</Page>
可以在代码隐藏中轻松创建内容对话框。然后,您可以在您提到的按钮的单击事件中使用该 C# 代码 运行。
你的另一个选择是在 XAML 上创建一个内容对话框,因为你已经在你的原始问题中发布了,这样当点击按钮时,你只需参考代码隐藏中的内容对话框并调用 ShowAsync()
方法。
我可以在此回复中编写示例代码,但为了将来这个问题与访问者相关,我鼓励您参考 Microsoft's documentation,它将得到更好的维护。我已经看过了,里面有具体的例子,对你有很大的帮助。
编辑: 发布示例代码作为参考。
MainPage.XAML
:
<Grid>
<Button
HorizontalAlignment="Center"
VerticalAlignment="Center"
Height="100" Width="250"
Content="Show Content"
FontSize="30px"
x:Name="ContentBtn"
Click="ContentBtn_Click"/>
<ContentDialog x:Name="ContentDialog"
Title="This is an example"
PrimaryButtonText="Ok"
CloseButtonText="Cancel"
DefaultButton="Primary">
</ContentDialog>
</Grid>
MainPage.XAML.cs
:
private async void ContentBtn_Click(object sender, RoutedEventArgs e) {
await ContentDialog.ShowAsync();
}