-
-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #46 from JeremyAnsel/input_box
Add InputBox dialog
- Loading branch information
Showing
4 changed files
with
116 additions
and
2 deletions.
There are no files selected for viewing
73 changes: 73 additions & 0 deletions
73
source/iNKORE.UI.WPF.Modern.Controls/Controls/InputBox/InputBox.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,73 @@ | ||
using System.Threading.Tasks; | ||
using System.Windows; | ||
using static iNKORE.UI.WPF.Modern.Controls.LocalizedDialogCommands; | ||
|
||
namespace iNKORE.UI.WPF.Modern.Controls | ||
{ | ||
public static class InputBox | ||
{ | ||
public static async Task<string> ShowAsync(object title, object prompt, string defaultResponse = "") | ||
{ | ||
ContentDialog dialog = BuildDialog(title, prompt, defaultResponse); | ||
ContentDialogResult result = await dialog.ShowAsync(); | ||
|
||
if (result != ContentDialogResult.Primary) | ||
{ | ||
return string.Empty; | ||
} | ||
|
||
InputBoxContent content = (InputBoxContent)dialog.Content; | ||
string response = content.responseTextControl.Text; | ||
return response; | ||
} | ||
|
||
public static async Task<string> ShowAsync(Window owner, object title, object prompt, string defaultResponse = "") | ||
{ | ||
ContentDialog dialog = BuildDialog(title, prompt, defaultResponse); | ||
ContentDialogResult result = await dialog.ShowAsync(owner); | ||
|
||
if (result != ContentDialogResult.Primary) | ||
{ | ||
return string.Empty; | ||
} | ||
|
||
InputBoxContent content = (InputBoxContent)dialog.Content; | ||
string response = content.responseTextControl.Text; | ||
return response; | ||
} | ||
|
||
public static async Task<string> ShowAsync(ContentDialogPlacement placement, object title, object prompt, string defaultResponse = "") | ||
{ | ||
ContentDialog dialog = BuildDialog(title, prompt, defaultResponse); | ||
ContentDialogResult result = await dialog.ShowAsync(placement); | ||
|
||
if (result != ContentDialogResult.Primary) | ||
{ | ||
return string.Empty; | ||
} | ||
|
||
InputBoxContent content = (InputBoxContent)dialog.Content; | ||
string response = content.responseTextControl.Text; | ||
return response; | ||
} | ||
|
||
private static ContentDialog BuildDialog(object title, object prompt, string defaultResponse) | ||
{ | ||
ContentDialog dialog = new() | ||
{ | ||
PrimaryButtonText = GetString(DialogBoxCommand.IDOK), | ||
CloseButtonText = GetString(DialogBoxCommand.IDCANCEL), | ||
DefaultButton = ContentDialogButton.Primary | ||
}; | ||
|
||
var content = new InputBoxContent(); | ||
dialog.Content = content; | ||
|
||
dialog.Title = title; | ||
content.promptTextControl.Content = prompt; | ||
content.responseTextControl.Text = defaultResponse; | ||
|
||
return dialog; | ||
} | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
source/iNKORE.UI.WPF.Modern.Controls/Controls/InputBox/InputBoxContent.xaml
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,18 @@ | ||
<UserControl x:Class="iNKORE.UI.WPF.Modern.Controls.InputBoxContent" | ||
x:ClassModifier="internal" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:local="clr-namespace:iNKORE.UI.WPF.Modern.Controls" xmlns:ui="http://schemas.inkore.net/lib/ui/wpf/modern" | ||
mc:Ignorable="d" | ||
d:DesignHeight="200" | ||
d:DesignWidth="400"> | ||
<ui:SimpleStackPanel Spacing="16" | ||
HorizontalAlignment="Stretch" | ||
VerticalAlignment="Stretch"> | ||
<ui:ContentPresenterEx x:Name="promptTextControl" TextWrapping="Wrap"/> | ||
<TextBox x:Name="responseTextControl" | ||
Text="" /> | ||
</ui:SimpleStackPanel> | ||
</UserControl> |
22 changes: 22 additions & 0 deletions
22
source/iNKORE.UI.WPF.Modern.Controls/Controls/InputBox/InputBoxContent.xaml.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,22 @@ | ||
using System.Windows; | ||
using System.Windows.Controls; | ||
using System.Windows.Input; | ||
|
||
namespace iNKORE.UI.WPF.Modern.Controls | ||
{ | ||
internal partial class InputBoxContent : UserControl | ||
{ | ||
public InputBoxContent() | ||
{ | ||
InitializeComponent(); | ||
|
||
Loaded += InputBoxContent_Loaded; | ||
} | ||
|
||
private void InputBoxContent_Loaded(object sender, RoutedEventArgs e) | ||
{ | ||
responseTextControl.Focus(); | ||
Keyboard.Focus(responseTextControl); | ||
} | ||
} | ||
} |
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