UWP:InApp通知未显示
我正在尝试使用Windows社区工具包示例应用程序中的InAppNotification控件,代码如下所示UWP:InApp通知未显示,uwp,uwp-xaml,windows-community-toolkit,Uwp,Uwp Xaml,Windows Community Toolkit,我正在尝试使用Windows社区工具包示例应用程序中的InAppNotification控件,代码如下所示 <Grid> <tk_ctl:InAppNotification x:Name="InAppNotification" ShowDismissButton="True" Width="252.5" Conten
<Grid>
<tk_ctl:InAppNotification
x:Name="InAppNotification"
ShowDismissButton="True"
Width="252.5"
Content="In App Notification example"
StackMode="Replace"/>
</Grid>
但是,当我运行应用程序时,我没有看到任何类型的弹出窗口。我错过什么了吗?另外,是否可以自定义InAppNotiifcation,使Dismise按钮位于顶部?您需要调用方法来显示通知
如果要自定义InAppNotification
,可以使用覆盖InAppNotification.Show(DataTemplate,Int32)
,它将DataTemplate
指定为通知的内容
您可以检查以下代码作为示例:
MainPage.xaml:
<Page.Resources>
<DataTemplate x:Key="InAppNotificationWithButtonsTemplate">
<UserControl>
<Grid>
<Grid x:Name="RootGrid" >
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<StackPanel x:Name="ButtonsStackPanel" Grid.ColumnSpan="2" Grid.Row="0"
Orientation="Horizontal" VerticalAlignment="Center">
<Button x:Name="YesButton" Content="Confirm" Width="100" Height="32" />
<Button x:Name="NoButton" Content="Dismiss" Width="100" Height="32" Margin="10 0 0 0" />
</StackPanel>
<TextBlock x:Name="TextBlock" Grid.ColumnSpan="2" Grid.Row="1"
Text="Do you Confirm it?" VerticalAlignment="Center" />
</Grid>
</Grid>
</UserControl>
</DataTemplate>
</Page.Resources>
<Grid>
<tk_ctl:InAppNotification x:Name="InAppNotification" ShowDismissButton="True"
Content="In App Notification example"
VerticalOffset="100"
HorizontalOffset="0"
StackMode="Replace">
</tk_ctl:InAppNotification>
</Grid>
……
object inAppNotificationWithButtonsTemplate;
bool isTemplatePresent = Resources.TryGetValue("InAppNotificationWithButtonsTemplate", out inAppNotificationWithButtonsTemplate);
if(isTemplatePresent&&inAppNotificationWithButtonsTemplate is DataTemplate)
{
InAppNotification.Show(inAppNotificationWithButtonsTemplate as DataTemplate);
}