Skip to content

Commit

Permalink
chore: adding dialog example to Uno sample
Browse files Browse the repository at this point in the history
  • Loading branch information
dansiegel committed Oct 7, 2023
1 parent e3a7f22 commit 17b6b70
Show file tree
Hide file tree
Showing 6 changed files with 156 additions and 0 deletions.
20 changes: 20 additions & 0 deletions e2e/Uno/ModuleA/Dialogs/AlertDialog.xaml
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>
27 changes: 27 additions & 0 deletions e2e/Uno/ModuleA/Dialogs/AlertDialog.xaml.cs
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();
}
}
}
40 changes: 40 additions & 0 deletions e2e/Uno/ModuleA/Dialogs/AlertDialogViewModel.cs
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");
}
}
16 changes: 16 additions & 0 deletions e2e/Uno/ModuleA/ViewModels/ViewAViewModel.cs
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)
{
}
}
9 changes: 9 additions & 0 deletions e2e/Uno/ModuleA/ViewModels/ViewBViewModel.cs
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)
{
}
}
44 changes: 44 additions & 0 deletions e2e/Uno/ModuleA/ViewModels/ViewModelBase.cs
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");
}
}

0 comments on commit 17b6b70

Please sign in to comment.