Skip to content

Commit

Permalink
Add backdrop for MessageBox
Browse files Browse the repository at this point in the history
  • Loading branch information
NotYoojun committed Dec 15, 2023
1 parent 77e7d9b commit 390db9e
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 28 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using iNKORE.UI.WPF.Modern.Common;
using iNKORE.UI.WPF.Modern.Controls.Helpers;
using iNKORE.UI.WPF.Modern.Controls.Primitives;
using iNKORE.UI.WPF.Modern.Helpers.Styles;
using System;
Expand Down Expand Up @@ -31,6 +32,8 @@ public MessageBoxResult Result
private Button NoButton { get; set; }
private Button CancelButton { get; set; }

public static BackdropType DefaultBackdropType { get; set; } = BackdropType.None;

static MessageBox()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(MessageBox), new FrameworkPropertyMetadata(typeof(MessageBox)));
Expand All @@ -41,6 +44,7 @@ public MessageBox()
SetValue(TemplateSettingsPropertyKey, new MessageBoxTemplateSettings());
var handler = new RoutedEventHandler((sender, e) => ApplyDarkMode());
ThemeManager.AddActualThemeChangedHandler(this, handler);
WindowHelper.SetSystemBackdropType(this, DefaultBackdropType);
Loaded += On_Loaded;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

<Style TargetType="local:MessageBox">
<Setter Property="Foreground" Value="{DynamicResource ContentDialogForeground}" />
<Setter Property="Background" Value="{DynamicResource ContentDialogBackground}" />
<!--<Setter Property="Background" Value="{DynamicResource ContentDialogBackground}" />-->
<Setter Property="BorderThickness" Value="{DynamicResource ContentDialogBorderWidth}" />
<Setter Property="BorderBrush" Value="{DynamicResource ContentDialogBorderBrush}" />
<!--<Setter Property="BorderBrush" Value="Transparent" />-->
Expand Down Expand Up @@ -63,9 +63,9 @@
HorizontalScrollBarVisibility="{TemplateBinding ScrollViewer.HorizontalScrollBarVisibility}"
IsTabStop="False"
VerticalScrollBarVisibility="{TemplateBinding ScrollViewer.VerticalScrollBarVisibility}">
<Border
<Border x:Name="Border_UpperBackground"
Padding="{DynamicResource ContentDialogPadding}"
Background="{DynamicResource ContentDialogTopOverlay}"
Background="{DynamicResource LayerOnAcrylicFillColorDefaultBrush}"
BorderBrush="{DynamicResource ContentDialogSeparatorBorderBrush}"
BorderThickness="{DynamicResource ContentDialogSeparatorThickness}">
<Grid>
Expand Down Expand Up @@ -283,10 +283,23 @@
<Trigger SourceName="DefaultButtonStatesListener" Property="CurrentStateName" Value="CancelAsDefaultButton">
<Setter TargetName="CancelButton" Property="Style" Value="{DynamicResource AccentButtonStyle}" />
</Trigger>

<Trigger Property="ui:WindowHelper.SystemBackdropType" Value="None">
<Setter TargetName="Border_UpperBackground" Property="Background" Value="{DynamicResource ContentDialogTopOverlay}"/>
</Trigger>

</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<!--<Trigger Property="ui:WindowHelper.SystemBackdropType" Value="Acrylic">
<Setter Property="WindowChrome.WindowChrome" Value="{DynamicResource AcrylicWindowChrome}"/>
</Trigger>-->
<Trigger Property="ui:WindowHelper.SystemBackdropType" Value="None">
<Setter Property="Background" Value="{DynamicResource ContentDialogBackground}"/>
</Trigger>
</Style.Triggers>
</Style>

</ResourceDictionary>
10 changes: 5 additions & 5 deletions source/iNKORE.UI.WPF.Modern.SampleApp/Controls/ControlExample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,9 @@ public string Xaml
}

public static readonly DependencyProperty XamlSourceProperty = DependencyProperty.Register("XamlSource", typeof(object), typeof(ControlExample), new PropertyMetadata(null));
public Uri XamlSource
public object XamlSource
{
get { return (Uri)GetValue(XamlSourceProperty); }
get { return (object)GetValue(XamlSourceProperty); }
set { SetValue(XamlSourceProperty, value); }
}

Expand All @@ -181,9 +181,9 @@ public string CSharp
}

public static readonly DependencyProperty CSharpSourceProperty = DependencyProperty.Register("CSharpSource", typeof(object), typeof(ControlExample), new PropertyMetadata(null));
public Uri CSharpSource
public string CSharpSource
{
get { return (Uri)GetValue(CSharpSourceProperty); }
get { return GetValue(CSharpSourceProperty) as string; }
set { SetValue(CSharpSourceProperty, value); }
}

Expand Down Expand Up @@ -446,7 +446,7 @@ string GetBestScreenshotName()
if (XamlSource != null)
{
// Most of them don't have this, but the xaml source name is a really good file name
string xamlSource = XamlSource.LocalPath;
string xamlSource = XamlSource.ToString();
string fileName = Path.GetFileNameWithoutExtension(xamlSource);
if (!String.IsNullOrWhiteSpace(fileName))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,21 @@ public string Code
}

public static readonly DependencyProperty CodeSourceFileProperty = DependencyProperty.Register("CodeSourceFile", typeof(object), typeof(SampleCodePresenter), new PropertyMetadata(null, OnCodeSourceFilePropertyChanged));
public Uri CodeSourceFile
public string CodeSourceFile
{
get { return (Uri)GetValue(CodeSourceFileProperty); }
get
{
var value = GetValue(CodeSourceFileProperty);

if(value is Uri uri)
{
return uri.OriginalString;
}
else
{
return value?.ToString();
}
}
set { SetValue(CodeSourceFileProperty, value); }
}

Expand Down Expand Up @@ -134,11 +146,11 @@ private void OnValueChanged(ControlExampleSubstitution sender, object e)
GenerateSyntaxHighlightedContent();
}

private Uri GetDerivedSource(Uri rawSource)
private Uri GetDerivedSource(string rawSource)
{
Uri derivedSource;
// Get the full path of the source string
string concatString = rawSource.OriginalString;
string concatString = rawSource;

if (concatString.StartsWith("/"))
{
Expand All @@ -164,9 +176,9 @@ private void GenerateSyntaxHighlightedContent()
}
}

private async void FormatAndRenderSampleFromFile(Uri source, ContentPresenter presenter, ILanguage highlightLanguage)
private async void FormatAndRenderSampleFromFile(string source, ContentPresenter presenter, ILanguage highlightLanguage)
{
if (source != null && source.OriginalString.EndsWith("txt"))
if (source != null && source.EndsWith("txt"))
{
Uri derivedSource = GetDerivedSource(source);
var file = Application.GetResourceStream(derivedSource);
Expand Down
2 changes: 1 addition & 1 deletion source/samples/WpfApp1/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
Title="MainWindow" Height="450" Width="800"
ResizeMode="CanMinimize"
ui:ThemeManager.IsThemeAware="True" ui:TitleBar.Height="40"
ui:TitleBar.ExtendViewIntoTitleBar="False"
ui:TitleBar.ExtendViewIntoTitleBar="False" ui:WindowHelper.SystemBackdropType="Acrylic"
ui:WindowHelper.UseModernWindowStyle="True"
ui:TitleBar.IsBackButtonVisible="False" ui:ThemeManager.RequestedTheme="Light"
ui:WindowHelper.CornerStyle="DoNotRound" Background="{x:Null}" Loaded="Window_Loaded">
Expand Down
37 changes: 24 additions & 13 deletions source/samples/WpfApp1/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,33 +81,44 @@ private void Button_MessageBox_Click(object sender, RoutedEventArgs e)
string title = "Some title";
string message = "This is a looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong test text!";

System.Windows.MessageBox.Show(message, title, MessageBoxButton.YesNoCancel, MessageBoxImage.Question);
System.Windows.MessageBox.Show("adawdawda", title, MessageBoxButton.YesNoCancel, MessageBoxImage.Question);
//System.Windows.MessageBox.Show(message, title, MessageBoxButton.YesNoCancel, MessageBoxImage.Question);
//System.Windows.MessageBox.Show("adawdawda", title, MessageBoxButton.YesNoCancel, MessageBoxImage.Question);
MessageBoxEx.Show("This is a test text!", "Some title", MessageBoxButton.YesNoCancel, MessageBoxImage.Question);
MessageBoxEx.Show("aaa");

MessageBoxEx.DefaultBackdropType = BackdropType.Acrylic;

MessageBoxEx.Show(message, title, MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.No);
MessageBoxEx.Show("redadwada", null, MessageBoxButton.OK, ((char)Symbol.Admin).ToString());
MessageBoxEx.Show("redadwada", null, MessageBoxButton.OK, SegoeIcons.Airplane);

MessageBoxEx.DefaultBackdropType = BackdropType.Mica;


MessageBoxEx.Show("redadwada", null, MessageBoxButton.OK, SegoeIcons.Airplane, MessageBoxResult.OK);
MessageBoxEx.ShowAsync(message, title, MessageBoxButton.YesNoCancel, MessageBoxImage.Question).GetAwaiter().GetResult();

MessageBoxEx.DefaultBackdropType = BackdropType.Tabbed;


MessageBoxEx.ShowAsync(message, title, MessageBoxButton.YesNoCancel, MessageBoxImage.Hand, MessageBoxResult.Cancel).GetAwaiter().GetResult();
MessageBoxEx.EnableLocalization = false;
MessageBoxEx.ShowAsync("Press Alt and you should see underscores!", null, MessageBoxButton.YesNoCancel, MessageBoxImage.Hand).GetAwaiter().GetResult();
}

private void Window_Loaded(object sender, RoutedEventArgs e)
{
WindowChrome.SetWindowChrome(this, new WindowChrome()
{
GlassFrameThickness = new Thickness(0, 1, 0, 0),
UseAeroCaptionButtons = false,
CornerRadius = new CornerRadius(0),
ResizeBorderThickness = new Thickness(4),
NonClientFrameEdges = NonClientFrameEdges.None,
CaptionHeight = 36d,
});
bool b = AcrylicHelper.Apply(this, true);
System.Windows.MessageBox.Show(b.ToString());
//WindowChrome.SetWindowChrome(this, new WindowChrome()
//{
// GlassFrameThickness = new Thickness(0, 1, 0, 0),
// UseAeroCaptionButtons = false,
// CornerRadius = new CornerRadius(0),
// ResizeBorderThickness = new Thickness(4),
// NonClientFrameEdges = NonClientFrameEdges.None,
// CaptionHeight = 36d,
//});
// bool b = AcrylicHelper.Apply(this, true);
//System.Windows.MessageBox.Show(b.ToString());
}
}
}

0 comments on commit 390db9e

Please sign in to comment.