-
-
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.
chore: adding dialog example to Uno sample
- Loading branch information
Showing
6 changed files
with
156 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<UserControl | ||
x:Class="ModuleA.Dialogs.AlertDialog" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:local="using:ModuleA" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
mc:Ignorable="d" | ||
d:DesignHeight="300" | ||
d:DesignWidth="400"> | ||
|
||
<StackPanel> | ||
<TextBlock Text="{Binding Title}" | ||
FontSize="20" | ||
FontWeight="Bold" /> | ||
<TextBlock Text="{Binding Message}" /> | ||
<Button Content="OK" | ||
Command="{Binding CloseCommand}" /> | ||
</StackPanel> | ||
</UserControl> |
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,27 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Runtime.InteropServices.WindowsRuntime; | ||
using Microsoft.UI.Xaml; | ||
using Microsoft.UI.Xaml.Controls; | ||
using Microsoft.UI.Xaml.Controls.Primitives; | ||
using Microsoft.UI.Xaml.Data; | ||
using Microsoft.UI.Xaml.Input; | ||
using Microsoft.UI.Xaml.Media; | ||
using Microsoft.UI.Xaml.Navigation; | ||
using Windows.Foundation; | ||
using Windows.Foundation.Collections; | ||
|
||
// The User Control item template is documented at https://go.microsoft.com/fwlink/?LinkId=234236 | ||
|
||
namespace ModuleA.Dialogs | ||
{ | ||
public sealed partial class AlertDialog : UserControl | ||
{ | ||
public AlertDialog() | ||
{ | ||
this.InitializeComponent(); | ||
} | ||
} | ||
} |
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,40 @@ | ||
namespace ModuleA.Dialogs; | ||
|
||
internal class AlertDialogViewModel : BindableBase, IDialogAware | ||
{ | ||
public AlertDialogViewModel() | ||
{ | ||
CloseCommand = new DelegateCommand(() => RequestClose.Invoke(new DialogResult(ButtonResult.OK))); | ||
} | ||
|
||
private string _title = string.Empty; | ||
public string Title | ||
{ | ||
get => _title; | ||
set => SetProperty(ref _title, value); | ||
} | ||
|
||
private string _message = string.Empty; | ||
public string Message | ||
{ | ||
get => _message; | ||
set => SetProperty(ref _message, value); | ||
} | ||
|
||
public DelegateCommand CloseCommand { get; } | ||
|
||
public DialogCloseListener RequestClose { get; } | ||
|
||
public bool CanCloseDialog() => true; | ||
|
||
public void OnDialogClosed() | ||
{ | ||
|
||
} | ||
|
||
public void OnDialogOpened(IDialogParameters parameters) | ||
{ | ||
Title = parameters.GetValue<string>("title"); | ||
Message = parameters.GetValue<string>("message"); | ||
} | ||
} |
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,16 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Collections.ObjectModel; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace ModuleA.ViewModels; | ||
|
||
internal class ViewAViewModel : ViewModelBase | ||
{ | ||
public ViewAViewModel(IRegionManager regionManager) | ||
: base(regionManager) | ||
{ | ||
} | ||
} |
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,9 @@ | ||
namespace ModuleA.ViewModels; | ||
|
||
internal class ViewBViewModel : ViewModelBase | ||
{ | ||
public ViewBViewModel(IRegionManager regionManager) | ||
: base(regionManager) | ||
{ | ||
} | ||
} |
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,44 @@ | ||
using System.Collections.ObjectModel; | ||
|
||
namespace ModuleA.ViewModels; | ||
|
||
internal class ViewModelBase : BindableBase, IRegionAware | ||
{ | ||
private readonly string _name; | ||
protected IRegionManager RegionManager { get; } | ||
|
||
protected ViewModelBase(IRegionManager regionManager) | ||
{ | ||
RegionManager = regionManager; | ||
Title = _name = GetType().Name.Replace("ViewModel", string.Empty); | ||
} | ||
|
||
private string _title = string.Empty; | ||
public string Title | ||
{ | ||
get => _title; | ||
set => SetProperty(ref _title, value); | ||
} | ||
|
||
private ObservableCollection<string> _messages = new(); | ||
public IEnumerable<string> Messages => _messages; | ||
|
||
|
||
public bool IsNavigationTarget(NavigationContext navigationContext) => | ||
navigationContext.NavigatedName() == _name; | ||
|
||
public void OnNavigatedFrom(NavigationContext navigationContext) | ||
{ | ||
_messages.Add("OnNavigatedFrom"); | ||
} | ||
|
||
public void OnNavigatedTo(NavigationContext navigationContext) | ||
{ | ||
if (navigationContext.Parameters.TryGetValue("title", out string title)) | ||
{ | ||
Title = title; | ||
} | ||
|
||
_messages.Add("OnNavigatedTo"); | ||
} | ||
} |