#uwp #uwp-xaml #windows-community-toolkit
#uwp #uwp-xaml #windows-community-toolkit
Вопрос:
Я пытаюсь использовать элемент управления InAppNotification из примера приложения Windows Community Toolkit и использовать приведенный ниже код
<Grid>
<tk_ctl:InAppNotification
x:Name="InAppNotification"
ShowDismissButton="True"
Width="252.5"
Content="In App Notification example"
StackMode="Replace"/>
</Grid>
Однако, когда я запускаю приложение, я не вижу всплывающего окна любого рода. Я что-то упустил? Также можно ли настроить InAppNotiifcation таким образом, чтобы кнопка «Отклонить» находилась вверху?
Ответ №1:
Вам нужно вызвать InAppNotification.Показать метод отображения вашего уведомления.
Если вы хотите настроить InAppNotification
, вы можете использовать переопределение InAppNotification.Show(DataTemplate, Int32)
, которое указывает a DataTemplate
в качестве содержимого уведомления.
Вы можете проверить следующий код в качестве примера:
Главная страница.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>
Главная страница.xaml.cs:
……
object inAppNotificationWithButtonsTemplate;
bool isTemplatePresent = Resources.TryGetValue("InAppNotificationWithButtonsTemplate", out inAppNotificationWithButtonsTemplate);
if(isTemplatePresentamp;amp;inAppNotificationWithButtonsTemplate is DataTemplate)
{
InAppNotification.Show(inAppNotificationWithButtonsTemplate as DataTemplate);
}