Skip to content

Commit

Permalink
Fix Growl PersianDate Exception HandyOrg/HandyControl#1586
Browse files Browse the repository at this point in the history
  • Loading branch information
ghost1372 committed May 18, 2024
1 parent f8bd345 commit 905d65b
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 42 deletions.
3 changes: 2 additions & 1 deletion src/Net_40/HandyControl_Net_40/Themes/Theme.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ Themes\Styles\Window.xaml
<conv:DoubleMinConverter x:Key="DoubleMinConverter" />
<conv:Object2StringConverter x:Key="Object2StringConverter" />
<conv:DataGridSelectAllButtonVisibilityConverter x:Key="DataGridSelectAllButtonVisibilityConverter" />
<conv:PersianDateConverter x:Key="PersianDateConverter" />
<Color x:Key="EffectShadowColor">#88000000</Color>
<sys:Double x:Key="LargeFontSize">24</sys:Double>
<sys:Double x:Key="HeadFontSize">20</sys:Double>
Expand Down Expand Up @@ -10339,7 +10340,7 @@ Themes\Styles\Window.xaml
<StackPanel VerticalAlignment="Center" Grid.Row="0" Grid.Column="1" Margin="0,10,10,10">
<TextBlock Text="{TemplateBinding Message}" Style="{StaticResource TextBlockDefault}" HorizontalAlignment="Left" TextWrapping="Wrap" />
<TextBlock Visibility="{Binding ShowDateTime,RelativeSource={RelativeSource TemplatedParent},Converter={StaticResource Boolean2VisibilityConverter}}" Text="{Binding Time,RelativeSource={RelativeSource AncestorType=hc:Growl},StringFormat=yyyy/MM/dd HH:mm:ss}" Style="{StaticResource TextBlockDefault}" Foreground="{DynamicResource SecondaryTextBrush}" HorizontalAlignment="Left" Margin="0,4,0,0" />
<TextBlock Visibility="{Binding ShowPersianDateTime,RelativeSource={RelativeSource TemplatedParent},Converter={StaticResource Boolean2VisibilityConverter}}" Text="{Binding Time,RelativeSource={RelativeSource AncestorType=hc:Growl},StringFormat=yyyy/MM/dd HH:mm:ss}" Style="{StaticResource TextBlockDefault}" Foreground="{DynamicResource SecondaryTextBrush}" HorizontalAlignment="Left" Margin="0,4,0,0" />
<TextBlock Visibility="{Binding ShowPersianDateTime,RelativeSource={RelativeSource TemplatedParent},Converter={StaticResource Boolean2VisibilityConverter}}" Text="{Binding Time,RelativeSource={RelativeSource AncestorType=hc:Growl}, Converter={StaticResource PersianDateConverter}}" Style="{StaticResource TextBlockDefault}" Foreground="{DynamicResource SecondaryTextBrush}" HorizontalAlignment="Left" Margin="0,4,0,0" />
</StackPanel>
<Button Grid.Row="0" Visibility="Collapsed" Margin="11,0" Name="PART_ButtonClose" Command="interactivity:ControlCommands.Close" Grid.Column="2" Background="Transparent" Style="{StaticResource ButtonCustom}" VerticalAlignment="Center" HorizontalAlignment="Center" Width="18" Height="18">
<Path FlowDirection="LeftToRight" Data="{StaticResource ErrorGeometry}" Stretch="Uniform" Fill="{DynamicResource SecondaryTextBrush}" />
Expand Down
3 changes: 2 additions & 1 deletion src/Net_GE45/HandyControl_Net_GE45/Themes/Theme.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ Source files:
<conv:DoubleMinConverter x:Key="DoubleMinConverter" />
<conv:Object2StringConverter x:Key="Object2StringConverter" />
<conv:DataGridSelectAllButtonVisibilityConverter x:Key="DataGridSelectAllButtonVisibilityConverter" />
<conv:PersianDateConverter x:Key="PersianDateConverter" />
<Color x:Key="EffectShadowColor">#88000000</Color>
<sys:Double x:Key="LargeFontSize">24</sys:Double>
<sys:Double x:Key="HeadFontSize">20</sys:Double>
Expand Down Expand Up @@ -10522,7 +10523,7 @@ Source files:
<StackPanel VerticalAlignment="Center" Grid.Row="0" Grid.Column="1" Margin="0,10,10,10">
<TextBlock Text="{TemplateBinding Message}" Style="{StaticResource TextBlockDefault}" HorizontalAlignment="Left" TextWrapping="Wrap" />
<TextBlock Visibility="{Binding ShowDateTime,RelativeSource={RelativeSource TemplatedParent},Converter={StaticResource Boolean2VisibilityConverter}}" Text="{Binding Time,RelativeSource={RelativeSource AncestorType=hc:Growl},StringFormat=yyyy/MM/dd HH:mm:ss}" Style="{StaticResource TextBlockDefault}" Foreground="{DynamicResource SecondaryTextBrush}" HorizontalAlignment="Left" Margin="0,4,0,0" />
<TextBlock Visibility="{Binding ShowPersianDateTime,RelativeSource={RelativeSource TemplatedParent},Converter={StaticResource Boolean2VisibilityConverter}}" Text="{Binding Time,RelativeSource={RelativeSource AncestorType=hc:Growl},StringFormat=yyyy/MM/dd HH:mm:ss}" Style="{StaticResource TextBlockDefault}" Foreground="{DynamicResource SecondaryTextBrush}" HorizontalAlignment="Left" Margin="0,4,0,0" />
<TextBlock Visibility="{Binding ShowPersianDateTime,RelativeSource={RelativeSource TemplatedParent},Converter={StaticResource Boolean2VisibilityConverter}}" Text="{Binding Time,RelativeSource={RelativeSource AncestorType=hc:Growl}, Converter={StaticResource PersianDateConverter}}" Style="{StaticResource TextBlockDefault}" Foreground="{DynamicResource SecondaryTextBrush}" HorizontalAlignment="Left" Margin="0,4,0,0" />
</StackPanel>
<Button Grid.Row="0" Visibility="Collapsed" Margin="11,0" Name="PART_ButtonClose" Command="interactivity:ControlCommands.Close" Grid.Column="2" Background="Transparent" Style="{StaticResource ButtonCustom}" VerticalAlignment="Center" HorizontalAlignment="Center" Width="18" Height="18">
<Path FlowDirection="LeftToRight" Data="{StaticResource ErrorGeometry}" Stretch="Uniform" Fill="{DynamicResource SecondaryTextBrush}" />
Expand Down
6 changes: 1 addition & 5 deletions src/Shared/HandyControl_Shared/Controls/Growl/Growl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ private static void ShowInternal(Panel panel, UIElement growl)
panel.Children.Add(growl);
}
}

private static void ShowGlobal(GrowlInfo growlInfo)
{
Application.Current.Dispatcher?.Invoke(
Expand All @@ -377,8 +377,6 @@ private static void ShowGlobal(GrowlInfo growlInfo)
var time = DateTime.Now;
if (growlInfo.ShowPersianDateTime)
{
System.Globalization.PersianCalendar pc = new System.Globalization.PersianCalendar();
time = new DateTime(pc.GetYear(DateTime.Now), pc.GetMonth(DateTime.Now), pc.GetDayOfMonth(DateTime.Now), DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second, DateTimeKind.Local);
showDateTime = false;
}
Expand Down Expand Up @@ -424,8 +422,6 @@ private static void Show(GrowlInfo growlInfo)
var time = DateTime.Now;
if (growlInfo.ShowPersianDateTime)
{
System.Globalization.PersianCalendar pc = new System.Globalization.PersianCalendar();
time = new DateTime(pc.GetYear(DateTime.Now), pc.GetMonth(DateTime.Now), pc.GetDayOfMonth(DateTime.Now), DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second, DateTimeKind.Local);
showDateTime = false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@
<Compile Include="$(MSBuildThisFileDirectory)HandyControls\ThemeManager\ResourceDictionaryEx.cs" />
<Compile Include="$(MSBuildThisFileDirectory)HandyControls\ThemeManager\ResourceDictionaryHelper.cs" />
<Compile Include="$(MSBuildThisFileDirectory)HandyControls\ThemeManager\Theme.cs" />
<Compile Include="$(MSBuildThisFileDirectory)HandyControls\Tools\Converter\PersianDateConverter.cs" />
<Compile Include="$(MSBuildThisFileDirectory)HandyControls\Tools\Helper\ThemeAnimationHelper.cs" />
<Compile Include="$(MSBuildThisFileDirectory)HandyControls\ThemeManager\ThemeDictionary.cs" />
<Compile Include="$(MSBuildThisFileDirectory)HandyControls\ThemeManager\ThemeManager.cs" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System.Globalization;
using System.Windows.Data;
using System;

namespace HandyControl.Tools.Converter;

public class PersianDateConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is DateTime dateTime)
{
var persianDate = new PersianDateTime(dateTime);
return $"{persianDate.ShamsiDate} {persianDate.Hour.ToString("00")}:{persianDate.Minute.ToString("00")}:{persianDate.Second.ToString("00")}";
}
return value;
}

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;

namespace HandyControl.Tools.Converter;
Expand Down
61 changes: 31 additions & 30 deletions src/Shared/HandyControl_Shared/Themes/Basic/Converters.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,37 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:converter="clr-namespace:HandyControl.Tools.Converter">

<converter:StringRepeatConverter x:Key="StringRepeatConverter"/>
<converter:Positive2Nagative x:Key="Positive2Nagative"/>
<converter:SpeedConverter x:Key="SpeedConverter"/>
<converter:ValueToBrushConverter x:Key="ValueToBrushConverter"/>
<converter:Boolean2BooleanReConverter x:Key="Boolean2BooleanReConverter"/>
<converter:Boolean2VisibilityReConverter x:Key="Boolean2VisibilityReConverter"/>
<converter:BooleanArr2VisibilityConverter x:Key="BooleanArr2VisibilityConverter"/>
<converter:StringRepeatConverter x:Key="StringRepeatConverter" />
<converter:Positive2Nagative x:Key="Positive2Nagative" />
<converter:SpeedConverter x:Key="SpeedConverter" />
<converter:ValueToBrushConverter x:Key="ValueToBrushConverter" />
<converter:Boolean2BooleanReConverter x:Key="Boolean2BooleanReConverter" />
<converter:Boolean2VisibilityReConverter x:Key="Boolean2VisibilityReConverter" />
<converter:BooleanArr2VisibilityConverter x:Key="BooleanArr2VisibilityConverter" />
<converter:BooleanArr2BooleanConverter x:Key="BooleanArr2BooleanConverter" />
<converter:Long2FileSizeConverter x:Key="Long2FileSizeConverter"/>
<converter:String2VisibilityConverter x:Key="String2VisibilityConverter"/>
<converter:String2VisibilityReConverter x:Key="String2VisibilityReConverter"/>
<BooleanToVisibilityConverter x:Key="Boolean2VisibilityConverter"/>
<converter:TreeViewItemMarginConverter x:Key="TreeViewItemMarginConverter"/>
<converter:Color2HexStringConverter x:Key="Color2HexStringConverter"/>
<converter:Object2BooleanConverter x:Key="Object2BooleanConverter"/>
<converter:Long2FileSizeConverter x:Key="Long2FileSizeConverter" />
<converter:String2VisibilityConverter x:Key="String2VisibilityConverter" />
<converter:String2VisibilityReConverter x:Key="String2VisibilityReConverter" />
<BooleanToVisibilityConverter x:Key="Boolean2VisibilityConverter" />
<converter:TreeViewItemMarginConverter x:Key="TreeViewItemMarginConverter" />
<converter:Color2HexStringConverter x:Key="Color2HexStringConverter" />
<converter:Object2BooleanConverter x:Key="Object2BooleanConverter" />
<converter:Object2BooleanReConverter x:Key="Object2BooleanReConverter" />
<converter:Boolean2StringConverter x:Key="Boolean2StringConverter"/>
<converter:Int2StringConverter x:Key="Int2StringConverter"/>
<converter:BorderClipConverter x:Key="BorderClipConverter"/>
<converter:BorderCircularClipConverter x:Key="BorderCircularClipConverter"/>
<converter:BorderCircularConverter x:Key="BorderCircularConverter"/>
<converter:Object2VisibilityConverter x:Key="Object2VisibilityConverter"/>
<converter:Object2VisibilityReConverter x:Key="Object2VisibilityReConverter"/>
<converter:Number2PercentageConverter x:Key="Number2PercentageConverter"/>
<converter:RectangleCircularConverter x:Key="RectangleCircularConverter"/>
<converter:ThicknessSplitConverter x:Key="ThicknessSplitConverter"/>
<converter:CornerRadiusSplitConverter x:Key="CornerRadiusSplitConverter"/>
<MenuScrollingVisibilityConverter x:Key="MenuScrollingVisibilityConverter"/>
<converter:Double2GridLengthConverter x:Key="Double2GridLengthConverter"/>
<converter:DoubleMinConverter x:Key="DoubleMinConverter"/>
<converter:Object2StringConverter x:Key="Object2StringConverter"/>
<converter:DataGridSelectAllButtonVisibilityConverter x:Key="DataGridSelectAllButtonVisibilityConverter"/>
<converter:Boolean2StringConverter x:Key="Boolean2StringConverter" />
<converter:Int2StringConverter x:Key="Int2StringConverter" />
<converter:BorderClipConverter x:Key="BorderClipConverter" />
<converter:BorderCircularClipConverter x:Key="BorderCircularClipConverter" />
<converter:BorderCircularConverter x:Key="BorderCircularConverter" />
<converter:Object2VisibilityConverter x:Key="Object2VisibilityConverter" />
<converter:Object2VisibilityReConverter x:Key="Object2VisibilityReConverter" />
<converter:Number2PercentageConverter x:Key="Number2PercentageConverter" />
<converter:RectangleCircularConverter x:Key="RectangleCircularConverter" />
<converter:ThicknessSplitConverter x:Key="ThicknessSplitConverter" />
<converter:CornerRadiusSplitConverter x:Key="CornerRadiusSplitConverter" />
<MenuScrollingVisibilityConverter x:Key="MenuScrollingVisibilityConverter" />
<converter:Double2GridLengthConverter x:Key="Double2GridLengthConverter" />
<converter:DoubleMinConverter x:Key="DoubleMinConverter" />
<converter:Object2StringConverter x:Key="Object2StringConverter" />
<converter:DataGridSelectAllButtonVisibilityConverter x:Key="DataGridSelectAllButtonVisibilityConverter" />
<converter:PersianDateConverter x:Key="PersianDateConverter" />
</ResourceDictionary>
2 changes: 1 addition & 1 deletion src/Shared/HandyControl_Shared/Themes/Styles/Growl.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
<StackPanel VerticalAlignment="Center" Grid.Row="0" Grid.Column="1" Margin="0,10,10,10">
<TextBlock Text="{TemplateBinding Message}" Style="{StaticResource TextBlockDefault}" HorizontalAlignment="Left" TextWrapping="Wrap"/>
<TextBlock Visibility="{Binding ShowDateTime,RelativeSource={RelativeSource TemplatedParent},Converter={StaticResource Boolean2VisibilityConverter}}" Text="{Binding Time,RelativeSource={RelativeSource AncestorType=hc:Growl},StringFormat=yyyy/MM/dd HH:mm:ss}" Style="{StaticResource TextBlockDefault}" Foreground="{DynamicResource SecondaryTextBrush}" HorizontalAlignment="Left" Margin="0,4,0,0"/>
<TextBlock Visibility="{Binding ShowPersianDateTime,RelativeSource={RelativeSource TemplatedParent},Converter={StaticResource Boolean2VisibilityConverter}}" Text="{Binding Time,RelativeSource={RelativeSource AncestorType=hc:Growl},StringFormat=yyyy/MM/dd HH:mm:ss}" Style="{StaticResource TextBlockDefault}" Foreground="{DynamicResource SecondaryTextBrush}" HorizontalAlignment="Left" Margin="0,4,0,0"/>
<TextBlock Visibility="{Binding ShowPersianDateTime,RelativeSource={RelativeSource TemplatedParent},Converter={StaticResource Boolean2VisibilityConverter}}" Text="{Binding Time,RelativeSource={RelativeSource AncestorType=hc:Growl}, Converter={StaticResource PersianDateConverter}}" Style="{StaticResource TextBlockDefault}" Foreground="{DynamicResource SecondaryTextBrush}" HorizontalAlignment="Left" Margin="0,4,0,0"/>
</StackPanel>
<Button Grid.Row="0" Visibility="Collapsed" Margin="11,0" Name="PART_ButtonClose" Command="interactivity:ControlCommands.Close" Grid.Column="2" Background="Transparent" Style="{StaticResource ButtonCustom}" VerticalAlignment="Center" HorizontalAlignment="Center" Width="18" Height="18">
<Path FlowDirection="LeftToRight" Data="{StaticResource ErrorGeometry}" Stretch="Uniform" Fill="{DynamicResource SecondaryTextBrush}"/>
Expand Down

0 comments on commit 905d65b

Please sign in to comment.