فهرست منبع

Add XAML usage sample

Max Katz 2 سال پیش
والد
کامیت
12863fe9c5
2فایلهای تغییر یافته به همراه29 افزوده شده و 5 حذف شده
  1. 22 4
      samples/ControlCatalog/Pages/NotificationsPage.xaml
  2. 7 1
      samples/ControlCatalog/Pages/NotificationsPage.xaml.cs

+ 22 - 4
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>

+ 7 - 1
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");
         }
     }
 }