Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ContentDialog control #502

Merged
merged 21 commits into from
Jan 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Wpf.Ui.Gallery/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ public partial class App : Application
services.AddTransient<SnackbarPage>();
services.AddTransient<SnackbarViewModel>();
services.AddTransient<DialogPage>();
services.AddTransient<ContentDialogPage>();
services.AddTransient<DialogViewModel>();
services.AddTransient<FlyoutPage>();
services.AddTransient<FlyoutViewModel>();
Expand Down
61 changes: 61 additions & 0 deletions src/Wpf.Ui.Gallery/Controls/TermsOfUseContentDialog.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<ui:ContentDialog
x:Class="Wpf.Ui.Gallery.Controls.TermsOfUseContentDialog"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Wpf.Ui.Gallery.Controls"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml"
Title="Terms of use"
d:DesignHeight="880"
d:DesignWidth="800"
ui:Design.Background="{DynamicResource ApplicationBackgroundBrush}"
ui:Design.Foreground="{DynamicResource TextFillColorPrimaryBrush}"
CloseButtonText="Close"
mc:Ignorable="d">

<ui:ContentDialog.Resources>
<Style BasedOn="{StaticResource {x:Type ui:ContentDialog}}" TargetType="{x:Type local:TermsOfUseContentDialog}" />
</ui:ContentDialog.Resources>

<Grid>
<StackPanel>
<TextBlock TextWrapping="WrapWithOverflow">
<Run>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque luctus malesuada mollis. Ut placerat dolor ac ligula consectetur, aliquam viverra odio dignissim. Donec in finibus tortor. Suspendisse eget ipsum vel arcu feugiat porttitor. Mauris et arcu pretium ipsum posuere tincidunt at a magna. Nullam finibus, arcu sit amet convallis sollicitudin, odio nisi efficitur mauris, quis aliquam dolor velit ac est. Integer quis ante velit. Etiam tincidunt, purus ut tempus auctor, sem augue congue urna, a vulputate mauris tortor a enim. Sed eros augue, ultrices quis neque eget, bibendum convallis lorem. Etiam luctus finibus consequat.
</Run><LineBreak />
<Run>Etiam viverra scelerisque risus et scelerisque. Praesent ipsum tellus, iaculis in augue quis, pharetra commodo dolor. In risus nisi, eleifend ut volutpat in, viverra a arcu. Vestibulum congue purus risus, rhoncus viverra ligula tempor in. Pellentesque ornare tempor ex, cursus suscipit mi dignissim a. Vivamus pulvinar at purus et feugiat. Donec consectetur malesuada consequat. Vestibulum est diam, sagittis in vehicula tempor, euismod ac ex. Nam in purus aliquet, ultricies ante at, tempus arcu. Praesent at orci accumsan, tincidunt leo eget, rhoncus nunc. Aenean eget fermentum justo.</Run><LineBreak />
<Run>
Nullam tincidunt tempor velit, eu commodo ipsum rhoncus sagittis. Nunc vel tortor nec ante pulvinar sagittis. Nullam eget sagittis orci. Nunc tristique nibh eu lacinia finibus. Donec eu volutpat nisi, eget fermentum quam. Aenean ut interdum dolor. Nunc nibh eros, aliquet eget augue tincidunt, congue tincidunt nisl.
</Run><LineBreak />
<Run>
Cras bibendum varius iaculis. In et rhoncus tortor. Nullam ac malesuada urna, eu gravida ante. Nam dictum consectetur leo. Quisque sem orci, auctor at ornare vulputate, maximus in enim. In in libero ac lorem tristique vulputate a vitae risus. Fusce vitae rhoncus lectus, quis lobortis tortor. Sed suscipit auctor lorem, eget finibus leo elementum et. Sed lobortis felis lectus, quis malesuada lacus sodales sed. Nulla vitae turpis id tellus convallis vulputate sed eu metus.
</Run>
</TextBlock>

<StackPanel
Margin="0,35,0,0"
HorizontalAlignment="Center"
VerticalAlignment="Center">

<TextBlock
x:Name="TextBlock"
HorizontalAlignment="Center"
VerticalAlignment="Center"
FontSize="16"
Foreground="Red"
Text="You must accept these terms of use to continue"
Visibility="Collapsed" />

<CheckBox
x:Name="CheckBox"
Margin="0,15,0,0"
HorizontalAlignment="Center"
VerticalAlignment="Center"
VerticalContentAlignment="Center"
Content="Agree"
FontSize="16" />
</StackPanel>
</StackPanel>
</Grid>
</ui:ContentDialog>
24 changes: 24 additions & 0 deletions src/Wpf.Ui.Gallery/Controls/TermsOfUseContentDialog.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System.Windows;
using System.Windows.Controls;
using Wpf.Ui.Controls;

namespace Wpf.Ui.Gallery.Controls;

public partial class TermsOfUseContentDialog : ContentDialog
{
public TermsOfUseContentDialog(ContentPresenter contentPresenter) : base(contentPresenter)
{
InitializeComponent();
}

protected override bool OnButtonClick(ContentDialogButton button)
{
if (CheckBox.IsChecked != false)
return true;

TextBlock.Visibility = Visibility.Visible;
CheckBox.Focus();

return false;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// This Source Code Form is subject to the terms of the MIT License.
// If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT.
// Copyright (C) Leszek Pomianowski and WPF UI Contributors.
// All Rights Reserved.

using System.Windows;
using Wpf.Ui.Controls;
using Wpf.Ui.Gallery.Controls;
using Wpf.Ui.Gallery.Views.Windows;

namespace Wpf.Ui.Gallery.ViewModels.Pages.DialogsAndFlyouts;

public partial class ContentDialogViewModel : ObservableObject
{
[ObservableProperty]
private string _dialogResultText = string.Empty;

[RelayCommand]
private async Task OnShowDialog(object content)
{
var window = (MainWindow)Application.Current.MainWindow!;
var dialog = new ContentDialog(window.RootContentDialog)
{
Title = "Save your work?",
Content = content,
PrimaryButtonText = "Save",
SecondaryButtonText = "Don't Save",
CloseButtonText = "Cancel",
DefaultButton = ContentDialogButton.Primary,
};

var result = await dialog.ShowAsync();

DialogResultText = result switch
{
ContentDialogResult.Primary => "User saved their work",
ContentDialogResult.Secondary => "User did not save their work",
_ => "User cancelled the dialog"
};
}

[RelayCommand]
private async Task OnShowSignInContentDialog()
{
var window = (MainWindow)Application.Current.MainWindow!;
var termsOfUseContentDialog = new TermsOfUseContentDialog(window.RootContentDialog);

await termsOfUseContentDialog.ShowAsync();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ public MainWindowViewModel(IServiceProvider serviceProvider)
{
new NavigationViewItem { Content = "Snackbar", TargetPageType = typeof(SnackbarPage) },
new NavigationViewItem { Content = "Dialog", TargetPageType = typeof(DialogPage) },
new NavigationViewItem { Content = "ContentDialog", TargetPageType = typeof(ContentDialogPage) },
new NavigationViewItem { Content = "Flyout", TargetPageType = typeof(FlyoutPage) },
new NavigationViewItem { Content = "MessageBox", TargetPageType = typeof(MessageBoxPage) },
}},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<Page
x:Class="Wpf.Ui.Gallery.Views.Pages.DialogsAndFlyouts.ContentDialogPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="clr-namespace:Wpf.Ui.Gallery.Controls"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:dialogsAndFlyouts="clr-namespace:Wpf.Ui.Gallery.ViewModels.Pages.DialogsAndFlyouts"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:system="clr-namespace:System;assembly=System.Runtime"
xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml"
Title="ContentDialog"
d:DataContext="{d:DesignInstance dialogsAndFlyouts:ContentDialogViewModel,
IsDesignTimeCreatable=False}"
d:DesignHeight="450"
d:DesignWidth="850"
ui:Design.Background="{DynamicResource ApplicationBackgroundBrush}"
ui:Design.Foreground="{DynamicResource TextFillColorPrimaryBrush}"
Foreground="{DynamicResource TextFillColorPrimaryBrush}"
mc:Ignorable="d">


<Page.Resources>
<ResourceDictionary>
<system:String x:Key="PageXamlUrl">https://github.com/lepoco/wpfui/blob/development/src/Wpf.Ui.Gallery/Views/Pages/DialogsAndFlyouts/ContentDialog.xaml</system:String>
<system:String x:Key="PageCsharpUrl">https://github.com/lepoco/wpfui/blob/development/src/Wpf.Ui.Gallery/ViewModels/Pages/DialogsAndFlyouts/ContentDialogViewModel.cs</system:String>

<StackPanel x:Key="DialogContent">
<TextBlock Text="Lorem ipsum dolor sit amet, adipisicing elit." TextWrapping="Wrap" />
<CheckBox Content="Upload your content to the cloud." />
</StackPanel>
</ResourceDictionary>
</Page.Resources>

<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<ui:DynamicScrollViewer
x:Name="PageScrollViewer"
Grid.RowSpan="2"
Padding="42">

<StackPanel>
<controls:GalleryControlPresenter HeaderText="ContentDialog">
<controls:GalleryControlPresenter.Content>
<StackPanel Orientation="Horizontal">
<Button
Command="{Binding ShowDialogCommand}"
CommandParameter="{StaticResource DialogContent}"
Content="Show" />

<TextBlock
Margin="15,0,0,0"
VerticalAlignment="Center"
FontSize="14"
Text="{Binding DialogResultText}" />
</StackPanel>
</controls:GalleryControlPresenter.Content>
</controls:GalleryControlPresenter>

<controls:GalleryControlPresenter Margin="0,36,0,0" HeaderText="Terms of Use ContentDialog example">
<controls:GalleryControlPresenter.Content>
<Button Command="{Binding ShowSignInContentDialogCommand}" Content="Show" />
</controls:GalleryControlPresenter.Content>
</controls:GalleryControlPresenter>
</StackPanel>
</ui:DynamicScrollViewer>
<controls:ControlDocumentationSummary
Grid.RowSpan="2"
Grid.Column="1"
CsharpUrl="{StaticResource PageCsharpUrl}"
XamlUrl="{StaticResource PageXamlUrl}" />
</Grid>
</Page>
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// This Source Code Form is subject to the terms of the MIT License.
// If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT.
// Copyright (C) Leszek Pomianowski and WPF UI Contributors.
// All Rights Reserved.


using System.Windows.Controls;
using Wpf.Ui.Gallery.ViewModels.Pages.DialogsAndFlyouts;

namespace Wpf.Ui.Gallery.Views.Pages.DialogsAndFlyouts;

public partial class ContentDialogPage : Page
{
public ContentDialogPage()
{
InitializeComponent();
DataContext = new ContentDialogViewModel();
}
}
5 changes: 5 additions & 0 deletions src/Wpf.Ui.Gallery/Views/Windows/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@
Grid.RowSpan="2"
Padding="0,42,0,0" />

<ContentPresenter
x:Name="RootContentDialog"
Grid.Row="0"
Grid.RowSpan="2" />

<ui:TitleBar
Title="{Binding ViewModel.ApplicationTitle}"
Grid.Row="0"
Expand Down
Loading