Skip to content

Commit

Permalink
improve picker on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
DevEddy committed Mar 30, 2023
1 parent 975fe58 commit f9e490a
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,13 @@ private static void AddEvents(IElementHandler? handler)

private static void RemoveEvents(IElementHandler? handler)
{
}

private static void FillWidth(IElementHandler? handler)
{
}

private static void OpenDropdown(IElementHandler? handler)
{
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,12 @@ private static void AddEvents(IElementHandler? handler)
private static void RemoveEvents(IElementHandler? handler)
{
}

private static void FillWidth(IElementHandler? handler)
{
}

private static void OpenDropdown(IElementHandler? handler)
{
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -281,13 +281,17 @@ private void SetupView()

_entryFrame.Content = _entryFrameContent;

var placeholderTapGesture = new TapGestureRecognizer();
placeholderTapGesture.Tapped += PlaceholderTapGestureOnTapped;
_placeholderLabel.GestureRecognizers.Add(placeholderTapGesture);

_placeholderLabel.SetBinding(Label.TextProperty, new Binding(nameof(Placeholder), source: this));

Children.Add(_entryFrame);
Children.Add(_placeholderLabel);
Children.Add(_errorLabel);
}

private static void ValidatableObjectChanged(BindableObject bindable, object oldValue, object newValue)
{
if (bindable is not EnhancedEntry enhancedEntry)
Expand Down Expand Up @@ -425,12 +429,20 @@ private static void NewViewOnHandlerChanged(object? sender, EventArgs e)
// https://learn.microsoft.com/en-us/dotnet/maui/user-interface/handlers/customize?view=net-maui-7.0#conditional-compilation
AddEvents(view.Handler);
RemoveBorder(view.Handler);
FillWidth(view.Handler);
}

private void PlaceholderTapGestureOnTapped(object? sender, TappedEventArgs e)
{
_mainEntryControl?.Focus();
OpenDropdown(_mainEntryControl?.Handler);
UpdateControlsState(true);
}

private void UpdateControlsState(bool isFocused)
{
var hasValue = !string.IsNullOrWhiteSpace(ValidatableObject?.StringValue);

if (HasError)
{
_placeholderLabel.TextColor = PlaceholderErrorColor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Input;
using Microsoft.UI.Xaml.Media;
using HorizontalAlignment = Microsoft.UI.Xaml.HorizontalAlignment;

// ReSharper disable once CheckNamespace
namespace Resolved.It.Maui.Controls;
Expand Down Expand Up @@ -54,4 +55,20 @@ private static void TextBox_GettingFocus(UIElement sender, GettingFocusEventArgs
textBox.Resources["TextControlBorderThemeThicknessFocused"] = textBox.BorderThickness;
textBox.Resources["TextControlBorderThemeThickness"] = textBox.BorderThickness;
}

private static void FillWidth(IElementHandler? handler)
{
if (handler?.PlatformView is not Microsoft.UI.Xaml.Controls.ComboBox comboBox)
return;

comboBox.HorizontalAlignment = HorizontalAlignment.Stretch;
}

private static void OpenDropdown(IElementHandler? handler)
{
if (handler?.PlatformView is not Microsoft.UI.Xaml.Controls.ComboBox comboBox)
return;

comboBox.IsDropDownOpen = true;
}
}

0 comments on commit f9e490a

Please sign in to comment.