Browse Source

Add XAML usage sample

pull/12178/head
Max Katz 3 years ago
parent
commit
12863fe9c5
  1. 26
      samples/ControlCatalog/Pages/NotificationsPage.xaml
  2. 8
      samples/ControlCatalog/Pages/NotificationsPage.xaml.cs

26
samples/ControlCatalog/Pages/NotificationsPage.xaml

@ -1,10 +1,28 @@
<UserControl xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:viewModels="using:ControlCatalog.ViewModels"
xmlns:system="clr-namespace:System;assembly=System.Runtime"
x:Class="ControlCatalog.Pages.NotificationsPage"
x:DataType="viewModels:NotificationViewModel">
<StackPanel Orientation="Vertical" Spacing="4" HorizontalAlignment="Left">
<Button Content="Show Standard Managed Notification" Command="{Binding ShowManagedNotificationCommand}" />
<Button Content="Show Custom Managed Notification" Command="{Binding ShowCustomManagedNotificationCommand}" />
</StackPanel>
<DockPanel>
<TextBlock DockPanel.Dock="Top"
Margin="2" Classes="h2" TextWrapping="Wrap">TopLevel bound notification manager.</TextBlock>
<StackPanel DockPanel.Dock="Top"
Orientation="Vertical" Spacing="4" HorizontalAlignment="Left">
<Button Content="Show Standard Managed Notification" Command="{Binding ShowManagedNotificationCommand}" />
<Button Content="Show Custom Managed Notification" Command="{Binding ShowCustomManagedNotificationCommand}" />
</StackPanel>
<TextBlock DockPanel.Dock="Top"
Margin="2" Classes="h2" TextWrapping="Wrap">XAML only notification manager.</TextBlock>
<Button DockPanel.Dock="Top"
Content="Show XAML only Notification" Command="{Binding #ControlNotifications.Show}">
<Button.CommandParameter>
<Notification Title="Title" Message="Message" OnClick="NotificationOnClick" />
</Button.CommandParameter>
</Button>
<Border Padding="10" BorderBrush="{DynamicResource SystemAccentColor}">
<WindowNotificationManager x:Name="ControlNotifications" />
</Border>
</DockPanel>
</UserControl>

8
samples/ControlCatalog/Pages/NotificationsPage.xaml.cs

@ -1,5 +1,6 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.Notifications;
using Avalonia.Markup.Xaml;
using ControlCatalog.ViewModels;
@ -27,7 +28,12 @@ namespace ControlCatalog.Pages
{
base.OnAttachedToVisualTree(e);
_viewModel.NotificationManager = new Avalonia.Controls.Notifications.WindowNotificationManager(TopLevel.GetTopLevel(this));
_viewModel.NotificationManager = new WindowNotificationManager(TopLevel.GetTopLevel(this)!);
}
public void NotificationOnClick()
{
this.Get<WindowNotificationManager>("ControlNotifications").Show("Notification clicked");
}
}
}

Loading…
Cancel
Save