Skip to content

Commit

Permalink
fix messagebox
Browse files Browse the repository at this point in the history
  • Loading branch information
ghost1372 committed Oct 3, 2020
1 parent 7913987 commit f5fdb34
Show file tree
Hide file tree
Showing 4 changed files with 131 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
using System.Windows.Controls.Primitives;
using System.Windows.Data;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Threading;
using CalendarBlackoutDatesCollection = Microsoft.Windows.Controls.CalendarBlackoutDatesCollection;
using CalendarDateChangedEventArgs = Microsoft.Windows.Controls.CalendarDateChangedEventArgs;
Expand All @@ -39,6 +40,46 @@ namespace HandyControl.Controls
[TemplateVisualState(Name = VisualStates.StateDisabled, GroupName = VisualStates.GroupCommon)]
public class PersianDatePicker : Control
{
public static readonly DependencyProperty SelectionBrushProperty =
TextBoxBase.SelectionBrushProperty.AddOwner(typeof(DatePicker));

public Brush SelectionBrush
{
get => (Brush)GetValue(SelectionBrushProperty);
set => SetValue(SelectionBrushProperty, value);
}

#if !(NET40 || NET45 || NET451 || NET452 || NET46 || NET461 || NET462 || NET47 || NET471 || NET472)

public static readonly DependencyProperty SelectionTextBrushProperty =
TextBoxBase.SelectionTextBrushProperty.AddOwner(typeof(DatePicker));

public Brush SelectionTextBrush
{
get => (Brush)GetValue(SelectionTextBrushProperty);
set => SetValue(SelectionTextBrushProperty, value);
}

#endif

public static readonly DependencyProperty SelectionOpacityProperty =
TextBoxBase.SelectionOpacityProperty.AddOwner(typeof(DatePicker));

public double SelectionOpacity
{
get => (double)GetValue(SelectionOpacityProperty);
set => SetValue(SelectionOpacityProperty, value);
}

public static readonly DependencyProperty CaretBrushProperty =
TextBoxBase.CaretBrushProperty.AddOwner(typeof(DatePicker));

public Brush CaretBrush
{
get => (Brush)GetValue(CaretBrushProperty);
set => SetValue(CaretBrushProperty, value);
}

#region Constants

private const string ElementRoot = "PART_Root";
Expand Down Expand Up @@ -765,6 +806,13 @@ public override void OnApplyTemplate()
_textBox.AddHandler(TextBox.TextChangedEvent, new TextChangedEventHandler(TextBox_TextChanged), true);
_textBox.AddHandler(TextBox.LostFocusEvent, new RoutedEventHandler(TextBox_LostFocus), true);

_textBox.SetBinding(SelectionBrushProperty, new Binding(SelectionBrushProperty.Name) { Source = this });
#if !(NET40 || NET45 || NET451 || NET452 || NET46 || NET461 || NET462 || NET47 || NET471 || NET472)
_textBox.SetBinding(SelectionTextBrushProperty, new Binding(SelectionTextBrushProperty.Name) { Source = this });
#endif
_textBox.SetBinding(SelectionOpacityProperty, new Binding(SelectionOpacityProperty.Name) { Source = this });
_textBox.SetBinding(CaretBrushProperty, new Binding(CaretBrushProperty.Name) { Source = this });

if (SelectedDate == null)
{
if (!string.IsNullOrEmpty(_defaultText))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Data;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Threading;
using HandyControl.Data;
using HandyControl.Interactivity;
Expand All @@ -20,6 +22,46 @@ namespace HandyControl.Controls
[TemplatePart(Name = ElementPopup, Type = typeof(Popup))]
public class PersianDateTimePicker : Control, IDataInput
{
public static readonly DependencyProperty SelectionBrushProperty =
TextBoxBase.SelectionBrushProperty.AddOwner(typeof(DateTimePicker));

public Brush SelectionBrush
{
get => (Brush)GetValue(SelectionBrushProperty);
set => SetValue(SelectionBrushProperty, value);
}

#if !(NET40 || NET45 || NET451 || NET452 || NET46 || NET461 || NET462 || NET47 || NET471 || NET472)

public static readonly DependencyProperty SelectionTextBrushProperty =
TextBoxBase.SelectionTextBrushProperty.AddOwner(typeof(DateTimePicker));

public Brush SelectionTextBrush
{
get => (Brush)GetValue(SelectionTextBrushProperty);
set => SetValue(SelectionTextBrushProperty, value);
}

#endif

public static readonly DependencyProperty SelectionOpacityProperty =
TextBoxBase.SelectionOpacityProperty.AddOwner(typeof(DateTimePicker));

public double SelectionOpacity
{
get => (double)GetValue(SelectionOpacityProperty);
set => SetValue(SelectionOpacityProperty, value);
}

public static readonly DependencyProperty CaretBrushProperty =
TextBoxBase.CaretBrushProperty.AddOwner(typeof(DateTimePicker));

public Brush CaretBrush
{
get => (Brush)GetValue(CaretBrushProperty);
set => SetValue(CaretBrushProperty, value);
}

#region Constants

private const string ElementRoot = "PART_Root";
Expand Down Expand Up @@ -316,31 +358,39 @@ public override void OnApplyTemplate()

_dropDownButton.Click += DropDownButton_Click;
_dropDownButton.MouseLeave += DropDownButton_MouseLeave;
if (SelectedDateTime == null)
if (_textBox != null)
{
_textBox.Text = DateTime.Now.ToString(DateTimeFormat);
}
_textBox.KeyDown += TextBox_KeyDown;
_textBox.TextChanged += TextBox_TextChanged;
_textBox.LostFocus += TextBox_LostFocus;
if (SelectedDateTime == null)
{
_textBox.Text = DateTime.Now.ToString(DateTimeFormat);
}

if (SelectedDateTime == null)
{
if (!string.IsNullOrEmpty(_defaultText))
_textBox.SetBinding(SelectionBrushProperty, new Binding(SelectionBrushProperty.Name) { Source = this });
#if !(NET40 || NET45 || NET451 || NET452 || NET46 || NET461 || NET462 || NET47 || NET471 || NET472)
_textBox.SetBinding(SelectionTextBrushProperty, new Binding(SelectionTextBrushProperty.Name) { Source = this });
#endif
_textBox.SetBinding(SelectionOpacityProperty, new Binding(SelectionOpacityProperty.Name) { Source = this });
_textBox.SetBinding(CaretBrushProperty, new Binding(CaretBrushProperty.Name) { Source = this });

_textBox.KeyDown += TextBox_KeyDown;
_textBox.TextChanged += TextBox_TextChanged;
_textBox.LostFocus += TextBox_LostFocus;

if (SelectedDateTime == null)
{
_textBox.Text = _defaultText;
SetSelectedDateTime();
if (!string.IsNullOrEmpty(_defaultText))
{
_textBox.Text = _defaultText;
SetSelectedDateTime();
}
}
else
{
_textBox.Text = DateTimeToString(SelectedDateTime.Value);
}
}
else
{
_textBox.Text = DateTimeToString(SelectedDateTime.Value);
}

if (_originalSelectedDateTime == null)
{
_originalSelectedDateTime = DateTime.Now;
}
_originalSelectedDateTime ??= DateTime.Now;
SetCurrentValue(DisplayDateTimeProperty, _originalSelectedDateTime);
}

Expand Down
17 changes: 9 additions & 8 deletions src/Shared/HandyControl_Shared/Controls/Window/MessageBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
using System.Media;
using System.Runtime.CompilerServices;
using System.Text;
using System.Windows;
using System.Windows.Controls;
Expand Down Expand Up @@ -500,7 +501,7 @@ private static void SetButtonStatus(MessageBox messageBox, MessageBoxButton mess
{
IsCancel = true,
IsDefault = true,
Content = ConfirmContent,
Content = messageBox.ConfirmContent,
Command = ControlCommands.Confirm,
Style = ResourceHelper.GetResource<Style>("MessageBoxButtonStyle")
};
Expand All @@ -510,15 +511,15 @@ private static void SetButtonStatus(MessageBox messageBox, MessageBoxButton mess
messageBox._showOk = true;
messageBox._buttonOk = new Button
{
Content = ConfirmContent,
Content = messageBox.ConfirmContent,
Command = ControlCommands.Confirm
};

messageBox._showCancel = true;
messageBox._buttonCancel = new Button
{
IsCancel = true,
Content = CancelContent,
Content = messageBox.CancelContent,
Command = ControlCommands.Cancel
};

Expand All @@ -540,14 +541,14 @@ private static void SetButtonStatus(MessageBox messageBox, MessageBoxButton mess
messageBox._showYes = true;
messageBox._buttonYes = new Button
{
Content = YesContent,
Content = messageBox.YesContent,
Command = ControlCommands.Yes
};

messageBox._showNo = true;
messageBox._buttonNo = new Button
{
Content = NoContent,
Content = messageBox.NoContent,
Command = ControlCommands.No
};

Expand All @@ -569,22 +570,22 @@ private static void SetButtonStatus(MessageBox messageBox, MessageBoxButton mess
messageBox._showYes = true;
messageBox._buttonYes = new Button
{
Content = YesContent,
Content = messageBox.YesContent,
Command = ControlCommands.Yes
};

messageBox._showNo = true;
messageBox._buttonNo = new Button
{
Content = NoContent,
Content = messageBox.NoContent,
Command = ControlCommands.No
};

messageBox._showCancel = true;
messageBox._buttonCancel = new Button
{
IsCancel = true,
Content = CancelContent,
Content = messageBox.CancelContent,
Command = ControlCommands.Cancel
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
<ColumnDefinition Width="30"/>
</Grid.ColumnDefinitions>
<Button Height="{x:Static system:Double.NaN}" Style="{StaticResource ButtonIcon}" Padding="7,6" hc:IconElement.Geometry="{StaticResource ClockGeometry}" x:Name="PART_Button" Grid.Column="1" Foreground="{Binding BorderBrush,ElementName=templateRoot}" Focusable="False" Grid.Row="0"/>
<hc:WatermarkTextBox Padding="{TemplateBinding Padding}" x:Name="PART_TextBox" HorizontalAlignment="Stretch" Grid.Column="0" Focusable="{TemplateBinding Focusable}" HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" Grid.Row="0" VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"/>
<hc:WatermarkTextBox Foreground="{TemplateBinding Foreground}" Padding="{TemplateBinding Padding}" x:Name="PART_TextBox" HorizontalAlignment="Stretch" Grid.Column="0" Focusable="{TemplateBinding Focusable}" HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" Grid.Row="0" VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"/>
<Popup TextElement.FontSize="12" Grid.Column="0" VerticalOffset="1" x:Name="PART_Popup" PopupAnimation="Fade" Placement="Bottom" PlacementTarget="{Binding ElementName=PART_TextBox}" StaysOpen="False"/>
</Grid>
</Border>
Expand Down Expand Up @@ -183,7 +183,7 @@
<ColumnDefinition Width="30"/>
</Grid.ColumnDefinitions>
<Button Height="{x:Static system:Double.NaN}" Style="{StaticResource ButtonIcon}" Padding="7,6" hc:IconElement.Geometry="{StaticResource ClockGeometry}" x:Name="PART_Button" Grid.Column="1" Foreground="{Binding BorderBrush,ElementName=templateRoot}" Focusable="False" Grid.Row="0"/>
<hc:WatermarkTextBox Padding="{TemplateBinding Padding}" x:Name="PART_TextBox" Watermark="{Binding Path=(hc:InfoElement.Placeholder),RelativeSource={RelativeSource TemplatedParent}}" HorizontalAlignment="Stretch" Grid.Column="0" Focusable="{TemplateBinding Focusable}" HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" Grid.Row="0" VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"/>
<hc:WatermarkTextBox Foreground="{TemplateBinding Foreground}" Padding="{TemplateBinding Padding}" x:Name="PART_TextBox" Watermark="{Binding Path=(hc:InfoElement.Placeholder),RelativeSource={RelativeSource TemplatedParent}}" HorizontalAlignment="Stretch" Grid.Column="0" Focusable="{TemplateBinding Focusable}" HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" Grid.Row="0" VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"/>
<Popup TextElement.FontSize="12" Grid.Column="0" VerticalOffset="1" x:Name="PART_Popup" PopupAnimation="Fade" Placement="Bottom" PlacementTarget="{Binding ElementName=PART_TextBox}" StaysOpen="False"/>
</Grid>
</Border>
Expand Down Expand Up @@ -281,7 +281,7 @@
<ColumnDefinition Width="30"/>
</Grid.ColumnDefinitions>
<Button Height="{x:Static system:Double.NaN}" Style="{StaticResource ButtonIcon}" Padding="7,6" hc:IconElement.Geometry="{StaticResource ClockGeometry}" x:Name="PART_Button" Grid.Column="1" Foreground="{Binding BorderBrush,ElementName=templateRoot}" Focusable="False" Grid.Row="0"/>
<hc:WatermarkTextBox Padding="{TemplateBinding Padding}" x:Name="PART_TextBox" Watermark="{Binding Path=(hc:InfoElement.Placeholder),RelativeSource={RelativeSource TemplatedParent}}" HorizontalAlignment="Stretch" Grid.Column="0" Focusable="{TemplateBinding Focusable}" HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" Grid.Row="0" VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"/>
<hc:WatermarkTextBox Foreground="{TemplateBinding Foreground}" Padding="{TemplateBinding Padding}" x:Name="PART_TextBox" Watermark="{Binding Path=(hc:InfoElement.Placeholder),RelativeSource={RelativeSource TemplatedParent}}" HorizontalAlignment="Stretch" Grid.Column="0" Focusable="{TemplateBinding Focusable}" HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" Grid.Row="0" VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"/>
<Popup TextElement.FontSize="12" Grid.Column="0" VerticalOffset="1" x:Name="PART_Popup" PopupAnimation="Fade" Placement="Bottom" PlacementTarget="{Binding ElementName=PART_TextBox}" StaysOpen="False"/>
</Grid>
</Border>
Expand Down Expand Up @@ -445,7 +445,7 @@
</Grid.ColumnDefinitions>
<Button Height="{x:Static system:Double.NaN}" Command="interactivity:ControlCommands.Clear" Visibility="Collapsed" Name="ButtonClear" Width="16" Grid.Column="1" Style="{StaticResource ButtonIcon}" Padding="0,6" hc:IconElement.Geometry="{StaticResource DeleteFillCircleGeometry}" Foreground="{Binding BorderBrush,ElementName=templateRoot}"/>
<Button Height="{x:Static system:Double.NaN}" Style="{StaticResource ButtonIcon}" Padding="2,6,7,6" hc:IconElement.Geometry="{StaticResource ClockGeometry}" x:Name="PART_Button" Grid.Column="2" Foreground="{Binding BorderBrush,ElementName=templateRoot}" Focusable="False" Grid.Row="0"/>
<hc:WatermarkTextBox Padding="{TemplateBinding Padding}" x:Name="PART_TextBox" Watermark="{Binding Path=(hc:InfoElement.Placeholder),RelativeSource={RelativeSource TemplatedParent}}" HorizontalAlignment="Stretch" Grid.Column="0" Focusable="{TemplateBinding Focusable}" HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" Grid.Row="0" VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"/>
<hc:WatermarkTextBox Foreground="{TemplateBinding Foreground}" Padding="{TemplateBinding Padding}" x:Name="PART_TextBox" Watermark="{Binding Path=(hc:InfoElement.Placeholder),RelativeSource={RelativeSource TemplatedParent}}" HorizontalAlignment="Stretch" Grid.Column="0" Focusable="{TemplateBinding Focusable}" HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" Grid.Row="0" VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"/>
<Popup TextElement.FontSize="12" Grid.Column="0" VerticalOffset="1" x:Name="PART_Popup" PopupAnimation="Fade" Placement="Bottom" PlacementTarget="{Binding ElementName=PART_TextBox}" StaysOpen="False"/>
</Grid>
</Border>
Expand Down Expand Up @@ -597,7 +597,7 @@
</Grid.ColumnDefinitions>
<Button Height="{x:Static system:Double.NaN}" Command="interactivity:ControlCommands.Clear" Visibility="Collapsed" Name="ButtonClear" Width="16" Grid.Column="1" Style="{StaticResource ButtonIcon}" Padding="0,6" hc:IconElement.Geometry="{StaticResource DeleteFillCircleGeometry}" Foreground="{Binding BorderBrush,ElementName=templateRoot}"/>
<Button Height="{x:Static system:Double.NaN}" Style="{StaticResource ButtonIcon}" Padding="2,6,7,6" hc:IconElement.Geometry="{StaticResource ClockGeometry}" x:Name="PART_Button" Grid.Column="2" Foreground="{Binding BorderBrush,ElementName=templateRoot}" Focusable="False" Grid.Row="0"/>
<hc:WatermarkTextBox Padding="{TemplateBinding Padding}" x:Name="PART_TextBox" Watermark="{Binding Path=(hc:InfoElement.Placeholder),RelativeSource={RelativeSource TemplatedParent}}" HorizontalAlignment="Stretch" Grid.Column="0" Focusable="{TemplateBinding Focusable}" HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" Grid.Row="0" VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"/>
<hc:WatermarkTextBox Foreground="{TemplateBinding Foreground}" Padding="{TemplateBinding Padding}" x:Name="PART_TextBox" Watermark="{Binding Path=(hc:InfoElement.Placeholder),RelativeSource={RelativeSource TemplatedParent}}" HorizontalAlignment="Stretch" Grid.Column="0" Focusable="{TemplateBinding Focusable}" HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" Grid.Row="0" VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"/>
<Popup TextElement.FontSize="12" Grid.Column="0" VerticalOffset="1" x:Name="PART_Popup" PopupAnimation="Fade" Placement="Bottom" PlacementTarget="{Binding ElementName=PART_TextBox}" StaysOpen="False"/>
</Grid>
</Border>
Expand Down

0 comments on commit f5fdb34

Please sign in to comment.