Skip to content

Commit

Permalink
1.2.1.5
Browse files Browse the repository at this point in the history
  • Loading branch information
Mochengvia committed May 30, 2024
1 parent 47c3c29 commit f784cc4
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,43 +38,41 @@
Value="2" />
<Setter Property="local:LabelHelper.ShadowColor"
Value="Gray" />
<Setter Property="ContentTemplate">
<Setter.Value>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<local:StateControl Margin="0,0,7,0"
Visibility="{Binding Icon, Converter={x:Static pw:Converters.NullToCollapseConverter}}"
CurrentState="{Binding Icon}"
VerticalAlignment="Center"
FontSize="{Binding Path=(local:IconHelper.FontSize), RelativeSource={RelativeSource AncestorType=Label}, Mode=OneWay}"
FontFamily="/Panuon.WPF.UI;component/Resources/Fonts/#PanuonIcon">
<local:StateItem State="Info">
<TextBlock Foreground="#80BEE8"
Text="&#xe92f;" />
</local:StateItem>
<local:StateItem State="Question">
<TextBlock Foreground="#80BEE8"
Text="&#xe937;" />
</local:StateItem>
<local:StateItem State="Warning">
<TextBlock Foreground="#F9D01A"
Text="&#xe931;" />
</local:StateItem>
<local:StateItem State="Error">
<TextBlock Foreground="#FF5656"
Text="&#xe933;" />
</local:StateItem>
<local:StateItem State="Success">
<TextBlock Foreground="#75CD43"
Text="&#xe935;" />
</local:StateItem>
</local:StateControl>
<TextBlock Text="{Binding Message}"
VerticalAlignment="Center" />
</StackPanel>
</DataTemplate>
</Setter.Value>
</Setter>
</Style>

<DataTemplate x:Key="{ComponentResourceKey ResourceId=ContentTemplateKey, TypeInTargetAssembly={x:Type local:Toast}}">
<StackPanel Orientation="Horizontal">
<local:StateControl Margin="0,0,7,0"
Visibility="{Binding Icon, Converter={x:Static pw:Converters.NullToCollapseConverter}}"
CurrentState="{Binding Icon}"
VerticalAlignment="Center"
FontSize="{Binding Path=(local:IconHelper.FontSize), RelativeSource={RelativeSource AncestorType=Label}, Mode=OneWay}"
FontFamily="/Panuon.WPF.UI;component/Resources/Fonts/#PanuonIcon">
<local:StateItem State="Info">
<TextBlock Foreground="#80BEE8"
Text="&#xe92f;" />
</local:StateItem>
<local:StateItem State="Question">
<TextBlock Foreground="#80BEE8"
Text="&#xe937;" />
</local:StateItem>
<local:StateItem State="Warning">
<TextBlock Foreground="#F9D01A"
Text="&#xe931;" />
</local:StateItem>
<local:StateItem State="Error">
<TextBlock Foreground="#FF5656"
Text="&#xe933;" />
</local:StateItem>
<local:StateItem State="Success">
<TextBlock Foreground="#75CD43"
Text="&#xe935;" />
</local:StateItem>
</local:StateControl>
<TextBlock Text="{Binding Message}"
VerticalAlignment="Center" />
</StackPanel>
</DataTemplate>

</ResourceDictionary>

Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ public class ToastSetting
#region Ctor
public ToastSetting()
{
LabelStyle = (Style)Application.Current.FindResource(Toast.LabelStyleKey);
SetCurrentValue(LabelStyleProperty, (Style)Application.Current.FindResource(Toast.LabelStyleKey));
SetCurrentValue(ContentTemplateProperty, (DataTemplate)Application.Current.FindResource(Toast.ContentTemplateKey));
}
#endregion

Expand All @@ -26,6 +27,17 @@ public Style LabelStyle
DependencyProperty.Register("LabelStyle", typeof(Style), typeof(ToastSetting));
#endregion

#region ContentTemplate
public DataTemplate ContentTemplate
{
get { return (DataTemplate)GetValue(ContentTemplateProperty); }
set { SetValue(ContentTemplateProperty, value); }
}

public static readonly DependencyProperty ContentTemplateProperty =
DependencyProperty.Register("ContentTemplate", typeof(DataTemplate), typeof(ToastSetting));
#endregion

#region DefaultPosition
public ToastPosition DefaultPosition
{
Expand Down
3 changes: 2 additions & 1 deletion SourceCode/SharedResources/Panuon.WPF.UI/Controls/WindowX.cs
Original file line number Diff line number Diff line change
Expand Up @@ -737,7 +737,8 @@ internal void CallToast(string message,
{
Icon = icon,
Message = message,
}
},
ContentTemplate = setting.ContentTemplate,
};
_toastCanvas.Children.Add(label);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ public Style WindowXStyle

#endregion


#region ContentTemplate
public DataTemplate ContentTemplate
{
Expand Down
20 changes: 8 additions & 12 deletions SourceCode/SharedResources/Panuon.WPF.UI/Helpers/Toast.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ public static class Toast
#region ComponentResourceKeys
public static ComponentResourceKey LabelStyleKey { get; } =
new ComponentResourceKey(typeof(Toast), nameof(LabelStyleKey));

public static ComponentResourceKey ContentTemplateKey { get; } =
new ComponentResourceKey(typeof(Toast), nameof(ContentTemplateKey));
#endregion

#region Methods
Expand Down Expand Up @@ -154,24 +157,17 @@ private static WindowX GetTargetWindow(ToastWindow window)
{
return windowX;
}
throw new ArgumentException("Toast : The main window in Application.Current is null, or the window is not of type Panuon.WPF.UI.WindowX. Please try to specify window parameter for Toast method.");
throw new InvalidOperationException("Toast can only be displayed on a window of type 'Panuon.WPF.UI.WindowX'. The value of 'Application.Current.MainWindow' is null, or its type is not 'WindowX'. To specify a different window for the Toast, use the overloaded methods that include a 'window' or 'targetWindow' parameter.");
default:
foreach (var loopObj in Application.Current.Windows)
{
if (loopObj is Window loopWindow
&& loopWindow.IsActive)
if (loopObj is WindowX loopWindowX
&& loopWindowX.IsActive)
{
if (loopWindow is WindowX)
{
return loopWindow as WindowX;
}
else
{
break;
}
return loopWindowX;
}
}
throw new ArgumentException("Toast : The activated window cannot be found in Application.Current, or the window is not of type Panuon.WPF.UI.WindowX. Please try to specify window parameter for Toast method.");
throw new InvalidOperationException("Toast can only be displayed on a window of type 'Panuon.WPF.UI.WindowX'. There is no active window, or the active window is not of type 'WindowX'. To specify a different window for the Toast, use the overloaded methods that include a 'window' or 'targetWindow' parameter.");
}
}
#endregion
Expand Down
14 changes: 14 additions & 0 deletions SourceCode/SharedResources/Panuon.WPF.UI/Helpers/ToastSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,20 @@ public Style LabelStyle
}
#endregion

#region ContentTemplate
public DataTemplate ContentTemplate
{
get
{
return Setting.ContentTemplate;
}
set
{
Setting.ContentTemplate = value;
}
}
#endregion

#region Spacing
public double Spacing
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@
ResourceDictionaryLocation.SourceAssembly
)]

[assembly: AssemblyVersion("1.2.1.4")]
[assembly: AssemblyFileVersion("1.2.1.4")]
[assembly: AssemblyVersion("1.2.1.5")]
[assembly: AssemblyFileVersion("1.2.1.5")]

0 comments on commit f784cc4

Please sign in to comment.