Skip to content

Commit

Permalink
Add a workaround way to override not selected text in DatePicker (thi…
Browse files Browse the repository at this point in the history
…s is temporary solution)
  • Loading branch information
SKProCH committed Nov 2, 2023
1 parent d41f04b commit 374d77b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
17 changes: 6 additions & 11 deletions Material.Styles/Converters/DatePickerTextConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,19 @@
using Avalonia.Data;
using Avalonia.Data.Converters;

namespace Material.Styles.Converters
{
public class DatePickerTextConverter : IMultiValueConverter
{
namespace Material.Styles.Converters {
public class DatePickerTextConverter : IMultiValueConverter {
public static DatePickerTextConverter Instance { get; } = new();

public object Convert(IList<object?> values, Type targetType, object? parameter, CultureInfo culture)
{
try
{
public object? Convert(IList<object?> values, Type targetType, object? parameter, CultureInfo culture) {
try {
return values[0] is UnsetValueType || values[0] == null
? "Not selected"
? values[2]
: values[0] is DateTimeOffset offset
? offset.ToString(values[1] as string)
: BindingOperations.DoNothing;
}
catch
{
catch {
return BindingOperations.DoNothing;
}
}
Expand Down
3 changes: 3 additions & 0 deletions Material.Styles/Resources/Themes/DatePicker.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
</StackPanel>
</Design.PreviewWith>

<x:String x:Key="MaterialDatePickerNotSelectedText">Not selected</x:String>

<ControlTheme x:Key="MaterialDatePicker" TargetType="DatePicker">
<Setter Property="Background" Value="Transparent" />
<Setter Property="BorderBrush" Value="Transparent" />
Expand Down Expand Up @@ -37,6 +39,7 @@
<MultiBinding Converter="{x:Static converters:DatePickerTextConverter.Instance}">
<TemplateBinding Property="SelectedDate" />
<TemplateBinding Property="assists:DatePickerAssist.DateTimeFormat" />
<DynamicResource ResourceKey="MaterialDatePickerNotSelectedText" />
</MultiBinding>
</TextBox.Text>
<TextBox.InnerRightContent>
Expand Down

0 comments on commit 374d77b

Please sign in to comment.