-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Sample Prism.Avalonia app with binding, sidebar, journaling, notifica…
…tion popups, and themes
- Loading branch information
1 parent
6a1a0de
commit 4bde483
Showing
19 changed files
with
691 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,13 @@ | ||
<Application xmlns="https://github.com/avaloniaui" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
x:Class="SampleApp.App" | ||
xmlns:local="using:SampleApp" | ||
RequestedThemeVariant="Default"> | ||
<!-- "Default" ThemeVariant follows system theme variant. "Dark" or "Light" are other available options. --> | ||
|
||
<Application.Styles> | ||
<FluentTheme /> | ||
|
||
<!-- Custom SVG glyphs --> | ||
<StyleInclude Source="avares://SampleApp/Styles/Icons.axaml" /> | ||
</Application.Styles> | ||
</Application> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
namespace SampleApp; | ||
|
||
public static class RegionNames | ||
{ | ||
public const string ContentRegion = "ContentRegion"; | ||
public const string FooterRegion = "FooterRegion"; | ||
public const string SidebarRegion = "SidebarRegion"; | ||
} |
13 changes: 13 additions & 0 deletions
13
e2e/Avalonia/PrismAvaloniaDemo/Services/INotificationService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using System; | ||
using Avalonia.Controls; | ||
|
||
namespace SampleApp.Services; | ||
|
||
public interface INotificationService | ||
{ | ||
int NotificationTimeout { get; set; } | ||
|
||
void SetHostWindow(TopLevel window); | ||
|
||
void Show(string title, string message, Action? onClick = null); | ||
} |
43 changes: 43 additions & 0 deletions
43
e2e/Avalonia/PrismAvaloniaDemo/Services/NotificationService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
using Avalonia.Controls.Notifications; | ||
|
||
namespace SampleApp.Services; | ||
|
||
public class NotificationService : INotificationService | ||
{ | ||
private WindowNotificationManager? _notificationManager; | ||
private int _notificationTimeout = 10; | ||
|
||
public int NotificationTimeout { get => _notificationTimeout; set => _notificationTimeout = (value < 0) ? 0 : value; } | ||
|
||
/// <summary>Set the host window.</summary> | ||
/// <param name="hostWindow">Parent window.</param> | ||
public void SetHostWindow(TopLevel hostWindow) | ||
{ | ||
var notificationManager = new WindowNotificationManager(hostWindow) | ||
{ | ||
Position = NotificationPosition.BottomRight, | ||
MaxItems = 4, | ||
Margin = new Thickness(0, 0, 15, 40) | ||
}; | ||
|
||
_notificationManager = notificationManager; | ||
} | ||
|
||
/// <summary>Display the notification.</summary> | ||
/// <param name="title">Title.</param> | ||
/// <param name="message">Message.</param> | ||
/// <param name="onClick">Optional OnClick action.</param> | ||
public void Show(string title, string message, Action? onClick = null) | ||
{ | ||
if (_notificationManager is { } nm) | ||
{ | ||
nm.Show( | ||
new Notification( | ||
title, | ||
message, | ||
NotificationType.Information, | ||
TimeSpan.FromSeconds(_notificationTimeout), | ||
onClick)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<Styles xmlns="https://github.com/avaloniaui" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> | ||
<Design.PreviewWith> | ||
<Border Padding="20"> | ||
<!-- Add Controls for Previewer Here --> | ||
<PathIcon Data="{StaticResource Menu}" /> | ||
</Border> | ||
</Design.PreviewWith> | ||
|
||
<!-- | ||
Add Styles Here | ||
References | ||
- https://avaloniaui.github.io/icons.html | ||
- https://docs.avaloniaui.net/tutorials/music-store-app/add-and-layout-controls | ||
- https://github.com/SKProCH/Material.Icons/blob/master/Material.Icons/MaterialIconDataProvider.PathData.cs | ||
--> | ||
<Style> | ||
<Style.Resources> | ||
<!-- Back button --> | ||
<StreamGeometry x:Key="arrow_reply_regular">M13.015,22.5 L20.0762716,29.5608928 C20.564427,30.0490482 20.564427,30.8405044 20.0762716,31.3286598 C19.62066,31.7842715 18.9008395,31.8146456 18.41,31.4197821 L18.3085047,31.3286598 L9.11611652,22.1362716 C8.66050485,21.68066 8.63013074,20.9608395 9.02499419,20.47 L9.11611652,20.3685047 L18.3085047,11.1761165 C18.79666,10.6879612 19.5881163,10.6879612 20.0762716,11.1761165 C20.5318833,11.6317282 20.5622574,12.3515486 20.167394,12.8423881 L20.0762716,12.9438835 L13.019,20 L22,20 C25.2536812,20 28.2794612,20.720575 30.9036216,22.0988501 L31.3145999,22.3219289 C33.9967941,23.8257725 36.1742275,26.0032059 37.6780711,28.6854001 C39.201579,31.4026669 40,34.5750724 40,38 C40,38.6903559 39.4403559,39.25 38.75,39.25 C38.0596441,39.25 37.5,38.6903559 37.5,38 C37.5,34.9958129 36.8076557,32.2448875 35.4974353,29.9080316 C34.2186616,27.6272628 32.3727372,25.7813384 30.0919684,24.5025647 C27.8849378,23.2651343 25.3085674,22.5788342 22.4983253,22.5063978 L22,22.5 L13.015,22.5 L20.0762716,29.5608928 L13.015,22.5 Z</StreamGeometry> | ||
|
||
<!-- Hamburger --> | ||
<StreamGeometry x:Key="Menu">M3,6H21V8H3V6M3,11H21V13H3V11M3,16H21V18H3V16Z</StreamGeometry> | ||
<StreamGeometry x:Key="MenuClose">M3 6H13V8H3V6M3 16H13V18H3V16M3 11H15V13H3V11M16 7L14.58 8.39L18.14 12L14.58 15.61L16 17L21 12L16 7Z</StreamGeometry> | ||
<StreamGeometry x:Key="MenuDown">M7,10L12,15L17,10H7Z</StreamGeometry> | ||
<StreamGeometry x:Key="MenuDownOutline">M18,9V10.5L12,16.5L6,10.5V9H18M12,13.67L14.67,11H9.33L12,13.67Z</StreamGeometry> | ||
<StreamGeometry x:Key="MenuLeft">M14,7L9,12L14,17V7Z</StreamGeometry> | ||
<StreamGeometry x:Key="MenuLeftOutline">M15,18H13.5L7.5,12L13.5,6H15V18M10.33,12L13,14.67V9.33L10.33,12Z</StreamGeometry> | ||
<StreamGeometry x:Key="MenuOpen">M21,15.61L19.59,17L14.58,12L19.59,7L21,8.39L17.44,12L21,15.61M3,6H16V8H3V6M3,13V11H13V13H3M3,18V16H16V18H3Z</StreamGeometry> | ||
<StreamGeometry x:Key="MenuRight">M10,17L15,12L10,7V17Z</StreamGeometry> | ||
<StreamGeometry x:Key="MenuRightOutline">M9,6H10.5L16.5,12L10.5,18H9V6M13.67,12L11,9.33V14.67L13.67,12Z</StreamGeometry> | ||
<StreamGeometry x:Key="MenuSwap">M12,6L7,11H17L12,6M7,13L12,18L17,13H7Z</StreamGeometry> | ||
<StreamGeometry x:Key="MenuSwapOutline">M12,3.5L6,9.5V11H18V9.5L12,3.5M12,6.33L14.67,9H9.33L12,6.33M6,13V14.5L12,20.5L18,14.5V13H6M9.33,15H14.67L12,17.67L9.33,15Z</StreamGeometry> | ||
<StreamGeometry x:Key="MenuUp">M7,15L12,10L17,15H7Z</StreamGeometry> | ||
<StreamGeometry x:Key="MenuUpOutline">M18,16V14.5L12,8.5L6,14.5V16H18M12,11.33L14.67,14H9.33L12,11.33Z</StreamGeometry> | ||
|
||
<!-- | ||
<StreamGeometry x:Key="Hamburger">M22 13C22 14.11 21.11 15 20 15H4C2.9 15 2 14.11 2 13S2.9 11 4 11H13L15.5 13L18 11H20C21.11 11 22 11.9 22 13M12 3C3 3 3 9 3 9H21C21 9 21 3 12 3M3 18C3 19.66 4.34 21 6 21H18C19.66 21 21 19.66 21 18V17H3V18Z</StreamGeometry> | ||
<StreamGeometry x:Key="HamburgerCheck">M21 9H3C3 9 3 3 12 3S21 9 21 9M13.35 17H3V18C3 19.66 4.34 21 6 21H13.35C13.13 20.37 13 19.7 13 19C13 18.3 13.13 17.63 13.35 17M21.86 13.73C21.95 13.5 22 13.26 22 13C22 11.9 21.11 11 20 11H11L8.5 13L6 11H4C2.9 11 2 11.9 2 13S2.9 15 4 15H14.54C15.64 13.78 17.23 13 19 13C20.04 13 21 13.26 21.86 13.73M21.34 15.84L17.75 19.43L16.16 17.84L15 19L17.75 22L22.5 17.25L21.34 15.84Z</StreamGeometry> | ||
<StreamGeometry x:Key="HamburgerMinus">M21 9H3C3 9 3 3 12 3S21 9 21 9M13.35 17H3V18C3 19.66 4.34 21 6 21H13.35C13.13 20.37 13 19.7 13 19C13 18.3 13.13 17.63 13.35 17M21.86 13.73C21.95 13.5 22 13.26 22 13C22 11.9 21.11 11 20 11H11L8.5 13L6 11H4C2.9 11 2 11.9 2 13S2.9 15 4 15H14.54C15.64 13.78 17.23 13 19 13C20.04 13 21 13.26 21.86 13.73M15 18V20H23V18H15Z</StreamGeometry> | ||
<StreamGeometry x:Key="HamburgerOff">M20 11C21.11 11 22 11.9 22 13S21.11 15 20 15H18.2L14.2 11H20M20.42 19.77L20.42 19.76L17.66 17H17.65L15.65 15H15.66L11.66 11H11.66L9.66 9H9.66L2.39 1.73L1.11 3L4.12 6C3 7.5 3 9 3 9H7.11L9.11 11H4C2.9 11 2 11.9 2 13S2.9 15 4 15H13.11L15.11 17H3V18C3 19.66 4.34 21 6 21H18C18.33 21 18.65 20.93 18.94 20.83L20.84 22.73L22.11 21.46L20.42 19.77M21 9C21 9 21 3 12 3C9.88 3 8.28 3.34 7.05 3.85L12.2 9H21Z</StreamGeometry> | ||
<StreamGeometry x:Key="HamburgerPlus">M21 9H3C3 9 3 3 12 3S21 9 21 9M13.35 17H3V18C3 19.66 4.34 21 6 21H13.35C13.13 20.37 13 19.7 13 19C13 18.3 13.13 17.63 13.35 17M21.86 13.73C21.95 13.5 22 13.26 22 13C22 11.9 21.11 11 20 11H11L8.5 13L6 11H4C2.9 11 2 11.9 2 13S2.9 15 4 15H14.54C15.64 13.78 17.23 13 19 13C20.04 13 21 13.26 21.86 13.73M20 18V15H18V18H15V20H18V23H20V20H23V18H20Z</StreamGeometry> | ||
<StreamGeometry x:Key="HamburgerRemove">M21 9H3C3 9 3 3 12 3S21 9 21 9M13.35 17H3V18C3 19.66 4.34 21 6 21H13.35C13.13 20.37 13 19.7 13 19C13 18.3 13.13 17.63 13.35 17M21.86 13.73C21.95 13.5 22 13.26 22 13C22 11.9 21.11 11 20 11H11L8.5 13L6 11H4C2.9 11 2 11.9 2 13S2.9 15 4 15H14.54C15.64 13.78 17.23 13 19 13C20.04 13 21 13.26 21.86 13.73M22.54 16.88L21.12 15.47L19 17.59L16.88 15.47L15.47 16.88L17.59 19L15.47 21.12L16.88 22.54L19 20.41L21.12 22.54L22.54 21.12L20.41 19L22.54 16.88Z</StreamGeometry> | ||
--> | ||
|
||
<!-- Dashboard --> | ||
<StreamGeometry x:Key="home_regular">M21.6062 5.85517C23.0048 4.71494 24.9952 4.71494 26.3938 5.85517L39.5688 16.5966C40.4736 17.3342 41 18.4492 41 19.628V39.1134C41 41.2599 39.2875 43 37.175 43H32.075C29.9625 43 28.25 41.2599 28.25 39.1134V29.7492C28.25 29.0337 27.6792 28.4536 26.975 28.4536H21.025C20.3208 28.4536 19.75 29.0337 19.75 29.7492V39.1134C19.75 41.2599 18.0375 43 15.925 43H10.825C8.71251 43 7 41.2599 7 39.1134V19.628C7 18.4493 7.52645 17.3342 8.43124 16.5966L21.6062 5.85517ZM24.7979 7.87612C24.3317 7.49604 23.6683 7.49604 23.2021 7.87612L10.0271 18.6175C9.72548 18.8634 9.55 19.2351 9.55 19.628V39.1134C9.55 39.8289 10.1208 40.4089 10.825 40.4089H15.925C16.6292 40.4089 17.2 39.8289 17.2 39.1134V29.7492C17.2 27.6027 18.9125 25.8626 21.025 25.8626H26.975C29.0875 25.8626 30.8 27.6027 30.8 29.7492V39.1134C30.8 39.8289 31.3708 40.4089 32.075 40.4089H37.175C37.8792 40.4089 38.45 39.8289 38.45 39.1134V19.628C38.45 19.2351 38.2745 18.8634 37.9729 18.6175L24.7979 7.87612Z</StreamGeometry> | ||
|
||
<!-- Lock --> | ||
<StreamGeometry x:Key="lock_regular">M12,2 C14.209139,2 16,3.790861 16,6 L16,8 L17.75,8 C18.9926407,8 20,9.00735931 20,10.25 L20,19.75 C20,20.9926407 18.9926407,22 17.75,22 L6.25,22 C5.00735931,22 4,20.9926407 4,19.75 L4,10.25 C4,9.00735931 5.00735931,8 6.25,8 L8,8 L8,6 C8,3.790861 9.790861,2 12,2 Z M17.75,9.5 L6.25,9.5 C5.83578644,9.5 5.5,9.83578644 5.5,10.25 L5.5,19.75 C5.5,20.1642136 5.83578644,20.5 6.25,20.5 L17.75,20.5 C18.1642136,20.5 18.5,20.1642136 18.5,19.75 L18.5,10.25 C18.5,9.83578644 18.1642136,9.5 17.75,9.5 Z M12.000125,13.5 C12.8285521,13.5 13.500125,14.1715729 13.500125,15 C13.500125,15.8284271 12.8285521,16.5 12.000125,16.5 C11.1716979,16.5 10.500125,15.8284271 10.500125,15 C10.500125,14.1715729 11.1716979,13.5 12.000125,13.5 Z M12,3.5 C10.6192881,3.5 9.5,4.61928813 9.5,6 L9.5,8 L14.5,8 L14.5,6 C14.5,4.61928813 13.3807119,3.5 12,3.5 Z</StreamGeometry> | ||
|
||
<!-- Settings --> | ||
<StreamGeometry x:Key="settings_regular">M14 9.50006C11.5147 9.50006 9.5 11.5148 9.5 14.0001C9.5 16.4853 11.5147 18.5001 14 18.5001C15.3488 18.5001 16.559 17.9066 17.3838 16.9666C18.0787 16.1746 18.5 15.1365 18.5 14.0001C18.5 13.5401 18.431 13.0963 18.3028 12.6784C17.7382 10.8381 16.0253 9.50006 14 9.50006ZM11 14.0001C11 12.3432 12.3431 11.0001 14 11.0001C15.6569 11.0001 17 12.3432 17 14.0001C17 15.6569 15.6569 17.0001 14 17.0001C12.3431 17.0001 11 15.6569 11 14.0001Z M21.7093 22.3948L19.9818 21.6364C19.4876 21.4197 18.9071 21.4515 18.44 21.7219C17.9729 21.9924 17.675 22.4693 17.6157 23.0066L17.408 24.8855C17.3651 25.273 17.084 25.5917 16.7055 25.682C14.9263 26.1061 13.0725 26.1061 11.2933 25.682C10.9148 25.5917 10.6336 25.273 10.5908 24.8855L10.3834 23.0093C10.3225 22.4731 10.0112 21.9976 9.54452 21.7281C9.07783 21.4586 8.51117 21.4269 8.01859 21.6424L6.29071 22.4009C5.93281 22.558 5.51493 22.4718 5.24806 22.1859C4.00474 20.8536 3.07924 19.2561 2.54122 17.5137C2.42533 17.1384 2.55922 16.7307 2.8749 16.4977L4.40219 15.3703C4.83721 15.0501 5.09414 14.5415 5.09414 14.0007C5.09414 13.4598 4.83721 12.9512 4.40162 12.6306L2.87529 11.5051C2.55914 11.272 2.42513 10.8638 2.54142 10.4882C3.08038 8.74734 4.00637 7.15163 5.24971 5.82114C5.51684 5.53528 5.93492 5.44941 6.29276 5.60691L8.01296 6.36404C8.50793 6.58168 9.07696 6.54881 9.54617 6.27415C10.0133 6.00264 10.3244 5.52527 10.3844 4.98794L10.5933 3.11017C10.637 2.71803 10.9245 2.39704 11.3089 2.31138C12.19 2.11504 13.0891 2.01071 14.0131 2.00006C14.9147 2.01047 15.8128 2.11485 16.6928 2.31149C17.077 2.39734 17.3643 2.71823 17.4079 3.11017L17.617 4.98937C17.7116 5.85221 18.4387 6.50572 19.3055 6.50663C19.5385 6.507 19.769 6.45838 19.9843 6.36294L21.7048 5.60568C22.0626 5.44818 22.4807 5.53405 22.7478 5.81991C23.9912 7.1504 24.9172 8.74611 25.4561 10.487C25.5723 10.8623 25.4386 11.2703 25.1228 11.5035L23.5978 12.6297C23.1628 12.95 22.9 13.4586 22.9 13.9994C22.9 14.5403 23.1628 15.0489 23.5988 15.3698L25.1251 16.4965C25.441 16.7296 25.5748 17.1376 25.4586 17.5131C24.9198 19.2536 23.9944 20.8492 22.7517 22.1799C22.4849 22.4657 22.0671 22.5518 21.7093 22.3948ZM16.263 22.1966C16.4982 21.4685 16.9889 20.8288 17.6884 20.4238C18.5702 19.9132 19.6536 19.8547 20.5841 20.2627L21.9281 20.8526C22.791 19.8538 23.4593 18.7013 23.8981 17.4552L22.7095 16.5778L22.7086 16.5771C21.898 15.98 21.4 15.0277 21.4 13.9994C21.4 12.9719 21.8974 12.0195 22.7073 11.4227L22.7085 11.4218L23.8957 10.545C23.4567 9.2988 22.7881 8.14636 21.9248 7.1477L20.5922 7.73425L20.5899 7.73527C20.1844 7.91463 19.7472 8.00722 19.3039 8.00663C17.6715 8.00453 16.3046 6.77431 16.1261 5.15465L16.1259 5.15291L15.9635 3.69304C15.3202 3.57328 14.6677 3.50872 14.013 3.50017C13.3389 3.50891 12.6821 3.57367 12.0377 3.69328L11.8751 5.15452C11.7625 6.16272 11.1793 7.05909 10.3019 7.56986C9.41937 8.0856 8.34453 8.14844 7.40869 7.73694L6.07273 7.14893C5.20949 8.14751 4.54092 9.29983 4.10196 10.5459L5.29181 11.4233C6.11115 12.0269 6.59414 12.9837 6.59414 14.0007C6.59414 15.0173 6.11142 15.9742 5.29237 16.5776L4.10161 17.4566C4.54002 18.7044 5.2085 19.8585 6.07205 20.8587L7.41742 20.2682C8.34745 19.8613 9.41573 19.9215 10.2947 20.4292C11.174 20.937 11.7593 21.832 11.8738 22.84L11.8744 22.8445L12.0362 24.3088C13.3326 24.5638 14.6662 24.5638 15.9626 24.3088L16.1247 22.8418C16.1491 22.6217 16.1955 22.4055 16.263 22.1966Z</StreamGeometry> | ||
</Style.Resources> | ||
</Style> | ||
</Styles> |
85 changes: 85 additions & 0 deletions
85
e2e/Avalonia/PrismAvaloniaDemo/ViewModels/DashboardViewModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
using System.Collections.Generic; | ||
using System.Collections.ObjectModel; | ||
using Avalonia; | ||
using Avalonia.Styling; | ||
using Prism.Commands; | ||
using SampleApp.Services; | ||
|
||
namespace SampleApp.ViewModels; | ||
|
||
public class DashboardViewModel : ViewModelBase | ||
{ | ||
private readonly INotificationService _notification; | ||
private int _counter = 0; | ||
private ObservableCollection<string> _listItems = new(); | ||
private int _listItemSelected = -1; | ||
private string _listItemText = string.Empty; | ||
private ThemeVariant? _themeSelected; | ||
|
||
public DashboardViewModel(INotificationService notifyService) | ||
{ | ||
_notification = notifyService; | ||
|
||
ThemeSelected = Application.Current!.RequestedThemeVariant; | ||
} | ||
|
||
public DelegateCommand CmdAddItem => new(() => | ||
{ | ||
_counter++; | ||
ListItems.Add($"Item Number: {_counter}"); | ||
// Optionally use, `Insert(0, ..)` to insert items at the top | ||
//ListItems.Insert(0, entry); | ||
}); | ||
|
||
public DelegateCommand CmdClearItems => new(() => | ||
{ | ||
ListItems.Clear(); | ||
}); | ||
|
||
public DelegateCommand CmdNotification => new(() => | ||
{ | ||
_notification.Show("Hello Prism!", "Notification Pop-up Message."); | ||
// Alternate OnClick action | ||
////_notification.Show("Hello Prism!", "Notification Pop-up Message.", () => | ||
////{ | ||
//// // Action to perform | ||
////}); | ||
}); | ||
|
||
public ObservableCollection<string> ListItems { get => _listItems; set => SetProperty(ref _listItems, value); } | ||
|
||
public int ListItemSelected | ||
{ | ||
get => _listItemSelected; | ||
set | ||
{ | ||
SetProperty(ref _listItemSelected, value); | ||
|
||
if (value == -1) | ||
return; | ||
|
||
ListItemText = ListItems[ListItemSelected]; | ||
} | ||
} | ||
|
||
public string ListItemText { get => _listItemText; set => SetProperty(ref _listItemText, value); } | ||
|
||
public ThemeVariant? ThemeSelected | ||
{ | ||
get => _themeSelected; | ||
set | ||
{ | ||
SetProperty(ref _themeSelected, value); | ||
Application.Current!.RequestedThemeVariant = _themeSelected; | ||
} | ||
} | ||
|
||
public List<ThemeVariant> ThemeStyles => new() | ||
{ | ||
ThemeVariant.Default, | ||
ThemeVariant.Dark, | ||
ThemeVariant.Light, | ||
}; | ||
} |
38 changes: 33 additions & 5 deletions
38
e2e/Avalonia/PrismAvaloniaDemo/ViewModels/MainWindowViewModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,41 @@ | ||
using Prism.Commands; | ||
using Prism.Navigation.Regions; | ||
|
||
using SampleApp.Views; | ||
|
||
namespace SampleApp.ViewModels; | ||
|
||
public class MainWindowViewModel : ViewModelBase | ||
{ | ||
public MainWindowViewModel() | ||
private readonly IRegionManager _regionManager; | ||
private bool _isPaneOpened; | ||
|
||
public MainWindowViewModel(IRegionManager regionManager) | ||
{ | ||
Title = "Welcome to Prism.Avalonia!"; | ||
// Since this is a basic ShellWindow, there's not much to do here. | ||
// For enterprise apps, you could register up subscriptions | ||
// or other startup background tasks so that they get triggered | ||
// on startup, rather than putting them in the DashboardViewModel. | ||
// | ||
// For example, initiate the pulling of News Feeds, etc. | ||
|
||
_regionManager = regionManager; | ||
Title = "Sample Prism.Avalonia SplitView!"; | ||
IsPaneOpened = true; | ||
} | ||
|
||
#pragma warning disable CA1822 // Mark members as static | ||
public string Greeting => "Hello from, Prism.Avalonia!"; | ||
#pragma warning restore CA1822 // Mark members as static | ||
public DelegateCommand CmdDashboard => new(() => | ||
{ | ||
// _journal.Clear(); | ||
_regionManager.RequestNavigate(RegionNames.ContentRegion, nameof(DashboardView)); | ||
}); | ||
|
||
public DelegateCommand CmdFlyoutMenu => new(() => | ||
{ | ||
IsPaneOpened = !IsPaneOpened; | ||
}); | ||
|
||
public DelegateCommand CmdSettings => new(() => _regionManager.RequestNavigate(RegionNames.ContentRegion, nameof(SettingsView))); | ||
|
||
public bool IsPaneOpened { get => _isPaneOpened; set => SetProperty(ref _isPaneOpened, value); } | ||
} |
35 changes: 35 additions & 0 deletions
35
e2e/Avalonia/PrismAvaloniaDemo/ViewModels/SettingsViewModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using SampleApp.Views; | ||
using Prism.Commands; | ||
using Prism.Navigation; | ||
using Prism.Navigation.Regions; | ||
|
||
namespace SampleApp.ViewModels | ||
{ | ||
public class SettingsViewModel : ViewModelBase | ||
{ | ||
private readonly IRegionManager _regionManager; | ||
|
||
public SettingsViewModel(IRegionManager regionManager) | ||
{ | ||
_regionManager = regionManager; | ||
Title = "Settings"; | ||
} | ||
|
||
public DelegateCommand CmdNavigateToChild => new DelegateCommand(() => | ||
{ | ||
var navParams = new NavigationParameters(); | ||
navParams.Add("key1", "Some text"); | ||
navParams.Add("key2", 999); | ||
_regionManager.RequestNavigate( | ||
RegionNames.ContentRegion, | ||
nameof(SubSettingsView), | ||
navParams); | ||
}); | ||
|
||
public override void OnNavigatedFrom(NavigationContext navigationContext) | ||
{ | ||
base.OnNavigatedFrom(navigationContext); | ||
} | ||
} | ||
} |
Oops, something went wrong.