Skip to content

Commit

Permalink
feat: Add support for Description property on common controls
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinZikmund committed Dec 13, 2021
1 parent 54ed773 commit 46e0956
Show file tree
Hide file tree
Showing 11 changed files with 156 additions and 96 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,7 @@ public partial class AutoSuggestBox : global::Windows.UI.Xaml.Controls.ItemsCon
}
}
#endif
#if __ANDROID__ || __IOS__ || NET461 || __WASM__ || __SKIA__ || __NETSTD_REFERENCE__ || __MACOS__
[global::Uno.NotImplemented("__ANDROID__", "__IOS__", "NET461", "__WASM__", "__SKIA__", "__NETSTD_REFERENCE__", "__MACOS__")]
public object Description
{
get
{
return (object)this.GetValue(DescriptionProperty);
}
set
{
this.SetValue(DescriptionProperty, value);
}
}
#endif
// Skipping already declared property Description
// Skipping already declared property AutoMaximizeSuggestionAreaProperty
// Skipping already declared property HeaderProperty
// Skipping already declared property IsSuggestionListOpenProperty
Expand All @@ -55,22 +42,15 @@ public object Description
// Skipping already declared property TextProperty
// Skipping already declared property UpdateTextOnSelectProperty
// Skipping already declared property QueryIconProperty
#if __ANDROID__ || __IOS__ || NET461 || __WASM__ || __SKIA__ || __NETSTD_REFERENCE__ || __MACOS__
#if __ANDROID__ || __IOS__ || NET461 || __WASM__ || __SKIA__ || __NETSTD_REFERENCE__ || __MACOS__
[global::Uno.NotImplemented("__ANDROID__", "__IOS__", "NET461", "__WASM__", "__SKIA__", "__NETSTD_REFERENCE__", "__MACOS__")]
public static global::Windows.UI.Xaml.DependencyProperty LightDismissOverlayModeProperty { get; } =
Windows.UI.Xaml.DependencyProperty.Register(
nameof(LightDismissOverlayMode), typeof(global::Windows.UI.Xaml.Controls.LightDismissOverlayMode),
typeof(global::Windows.UI.Xaml.Controls.AutoSuggestBox),
new FrameworkPropertyMetadata(default(global::Windows.UI.Xaml.Controls.LightDismissOverlayMode)));
#endif
#if __ANDROID__ || __IOS__ || NET461 || __WASM__ || __SKIA__ || __NETSTD_REFERENCE__ || __MACOS__
[global::Uno.NotImplemented("__ANDROID__", "__IOS__", "NET461", "__WASM__", "__SKIA__", "__NETSTD_REFERENCE__", "__MACOS__")]
public static global::Windows.UI.Xaml.DependencyProperty DescriptionProperty { get; } =
Windows.UI.Xaml.DependencyProperty.Register(
nameof(Description), typeof(object),
typeof(global::Windows.UI.Xaml.Controls.AutoSuggestBox),
new FrameworkPropertyMetadata(default(object)));
#endif
// Skipping already declared property DescriptionProperty
// Skipping already declared method Windows.UI.Xaml.Controls.AutoSuggestBox.AutoSuggestBox()
// Forced skipping of method Windows.UI.Xaml.Controls.AutoSuggestBox.AutoSuggestBox()
// Forced skipping of method Windows.UI.Xaml.Controls.AutoSuggestBox.MaxSuggestionListHeight.get
Expand Down
24 changes: 2 additions & 22 deletions src/Uno.UI/Generated/3.0.0.0/Windows.UI.Xaml.Controls/ComboBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,20 +128,7 @@ public string Text
}
}
#endif
#if __ANDROID__ || __IOS__ || NET461 || __WASM__ || __SKIA__ || __NETSTD_REFERENCE__ || __MACOS__
[global::Uno.NotImplemented("__ANDROID__", "__IOS__", "NET461", "__WASM__", "__SKIA__", "__NETSTD_REFERENCE__", "__MACOS__")]
public object Description
{
get
{
return (object)this.GetValue(DescriptionProperty);
}
set
{
this.SetValue(DescriptionProperty, value);
}
}
#endif
// Skipping already declared property Description
// Skipping already declared property IsDropDownOpenProperty
// Skipping already declared property MaxDropDownHeightProperty
// Skipping already declared property HeaderProperty
Expand Down Expand Up @@ -172,14 +159,7 @@ public object Description
typeof(global::Windows.UI.Xaml.Controls.ComboBox),
new FrameworkPropertyMetadata(default(global::Windows.UI.Xaml.Media.Brush)));
#endif
#if __ANDROID__ || __IOS__ || NET461 || __WASM__ || __SKIA__ || __NETSTD_REFERENCE__ || __MACOS__
[global::Uno.NotImplemented("__ANDROID__", "__IOS__", "NET461", "__WASM__", "__SKIA__", "__NETSTD_REFERENCE__", "__MACOS__")]
public static global::Windows.UI.Xaml.DependencyProperty DescriptionProperty { get; } =
Windows.UI.Xaml.DependencyProperty.Register(
nameof(Description), typeof(object),
typeof(global::Windows.UI.Xaml.Controls.ComboBox),
new FrameworkPropertyMetadata(default(object)));
#endif
// Skipping already declared property DescriptionProperty
#if __ANDROID__ || __IOS__ || NET461 || __WASM__ || __SKIA__ || __NETSTD_REFERENCE__ || __MACOS__
[global::Uno.NotImplemented("__ANDROID__", "__IOS__", "NET461", "__WASM__", "__SKIA__", "__NETSTD_REFERENCE__", "__MACOS__")]
public static global::Windows.UI.Xaml.DependencyProperty IsEditableProperty { get; } =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,20 +85,7 @@ public bool PreventKeyboardDisplayOnProgrammaticFocus
}
}
#endif
#if __ANDROID__ || __IOS__ || NET461 || __WASM__ || __SKIA__ || __NETSTD_REFERENCE__ || __MACOS__
[global::Uno.NotImplemented("__ANDROID__", "__IOS__", "NET461", "__WASM__", "__SKIA__", "__NETSTD_REFERENCE__", "__MACOS__")]
public object Description
{
get
{
return (object)this.GetValue(DescriptionProperty);
}
set
{
this.SetValue(DescriptionProperty, value);
}
}
#endif
// Skipping already declared property Description
#if __ANDROID__ || __IOS__ || NET461 || __WASM__ || __SKIA__ || __NETSTD_REFERENCE__ || __MACOS__
[global::Uno.NotImplemented("__ANDROID__", "__IOS__", "NET461", "__WASM__", "__SKIA__", "__NETSTD_REFERENCE__", "__MACOS__")]
public bool CanPasteClipboardContent
Expand Down Expand Up @@ -157,14 +144,7 @@ public bool CanPasteClipboardContent
typeof(global::Windows.UI.Xaml.Controls.PasswordBox),
new FrameworkPropertyMetadata(default(bool)));
#endif
#if __ANDROID__ || __IOS__ || NET461 || __WASM__ || __SKIA__ || __NETSTD_REFERENCE__ || __MACOS__
[global::Uno.NotImplemented("__ANDROID__", "__IOS__", "NET461", "__WASM__", "__SKIA__", "__NETSTD_REFERENCE__", "__MACOS__")]
public static global::Windows.UI.Xaml.DependencyProperty DescriptionProperty { get; } =
Windows.UI.Xaml.DependencyProperty.Register(
nameof(Description), typeof(object),
typeof(global::Windows.UI.Xaml.Controls.PasswordBox),
new FrameworkPropertyMetadata(default(object)));
#endif
// Skipping already declared property DescriptionProperty
#if __ANDROID__ || __IOS__ || NET461 || __WASM__ || __SKIA__ || __NETSTD_REFERENCE__ || __MACOS__
[global::Uno.NotImplemented("__ANDROID__", "__IOS__", "NET461", "__WASM__", "__SKIA__", "__NETSTD_REFERENCE__", "__MACOS__")]
public static global::Windows.UI.Xaml.DependencyProperty SelectionFlyoutProperty { get; } =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ public string Text
set => this.SetValue(QueryIconProperty, value);
}

public object Description
{
get => this.GetValue(DescriptionProperty);
set => this.SetValue(DescriptionProperty, value);
}

public static global::Windows.UI.Xaml.DependencyProperty MaxSuggestionListHeightProperty { get; } =
Windows.UI.Xaml.DependencyProperty.Register(
"MaxSuggestionListHeight", typeof(double),
Expand Down Expand Up @@ -135,6 +141,12 @@ public string Text
typeof(global::Windows.UI.Xaml.Controls.AutoSuggestBox),
new FrameworkPropertyMetadata(default(global::Windows.UI.Xaml.Controls.IconElement), propertyChangedCallback: (s, e) => (s as AutoSuggestBox)?.UpdateQueryButton()));

public static global::Windows.UI.Xaml.DependencyProperty DescriptionProperty { get; } =
Windows.UI.Xaml.DependencyProperty.Register(
nameof(Description), typeof(object),
typeof(global::Windows.UI.Xaml.Controls.AutoSuggestBox),
new FrameworkPropertyMetadata(default(object), propertyChangedCallback: (s, e) => (s as AutoSuggestBox)?.UpdateDescriptionVisibility(false)));

public event TypedEventHandler<AutoSuggestBox, AutoSuggestBoxSuggestionChosenEventArgs> SuggestionChosen;
public event TypedEventHandler<AutoSuggestBox, AutoSuggestBoxTextChangedEventArgs> TextChanged;
public event TypedEventHandler<AutoSuggestBox, AutoSuggestBoxQuerySubmittedEventArgs> QuerySubmitted;
Expand Down
16 changes: 16 additions & 0 deletions src/Uno.UI/UI/Xaml/Controls/AutoSuggestBox/AutoSuggestBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ protected override void OnApplyTemplate()

UpdateQueryButton();
UpdateTextBox();
UpdateDescriptionVisibility(true);

_textBoxBinding = new BindingPath("Text", null) { DataContext = _textBox, ValueChangedListener = this };

Expand Down Expand Up @@ -440,5 +441,20 @@ private static void OnTextChanged(DependencyObject dependencyObject, DependencyP
});
}
}

private void UpdateDescriptionVisibility(bool initialization)
{
if (initialization && Description == null)
{
// Avoid loading DescriptionPresenter element in template if not needed.
return;
}

var descriptionPresenter = this.FindName("DescriptionPresenter") as ContentPresenter;
if (descriptionPresenter != null)
{
descriptionPresenter.Visibility = Description != null ? Visibility.Visible : Visibility.Collapsed;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public string DayOfWeekFormat
}

public static DependencyProperty DescriptionProperty { get; } = DependencyProperty.Register(
"Description", typeof(object), typeof(CalendarDatePicker), new FrameworkPropertyMetadata(default(object)));
"Description", typeof(object), typeof(CalendarDatePicker), new FrameworkPropertyMetadata(default(object), propertyChangedCallback: (s, e) => (s as CalendarDatePicker)?.UpdateDescriptionVisibility(false)));

#if __IOS__ || __MACOS__
public new // .Description already exists on NSObject (both macOS & iOS)
Expand All @@ -63,7 +63,7 @@ public string DayOfWeekFormat
#endif
object Description
{
get => (string)GetValue(DescriptionProperty);
get => GetValue(DescriptionProperty);
set => SetValue(DescriptionProperty, value);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ internal override void OnPropertyChanged2(DependencyPropertyChangedEventArgs arg
overlayMode = LightDismissOverlayMode;
((FlyoutBase)m_tpFlyout).LightDismissOverlayMode = overlayMode;
}
}
}
}

protected override void OnApplyTemplate()
Expand Down Expand Up @@ -279,6 +279,9 @@ protected override void OnApplyTemplate()

UpdateVisualState();

// TODO: Uno specific: This logic should later move to Control to match WinUI
UpdateDescriptionVisibility(true);

void OnFlyoutOpened(object sender, object eventArgs)
{
IsCalendarOpen = true;
Expand Down Expand Up @@ -1105,5 +1108,20 @@ internal void GetCurrentFormattedDate(out string value)
value = m_tpDateText.Text;
}
}

private void UpdateDescriptionVisibility(bool initialization)
{
if (initialization && Description == null)
{
// Avoid loading DescriptionPresenter element in template if not needed.
return;
}

var descriptionPresenter = this.FindName("DescriptionPresenter") as ContentPresenter;
if (descriptionPresenter != null)
{
descriptionPresenter.Visibility = Description != null ? Visibility.Visible : Visibility.Collapsed;
}
}
}
}
32 changes: 32 additions & 0 deletions src/Uno.UI/UI/Xaml/Controls/ComboBox/ComboBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ protected override void OnApplyTemplate()

UpdateHeaderVisibility();
UpdateContentPresenter();
UpdateDescriptionVisibility(true);

if (_contentPresenter != null)
{
Expand Down Expand Up @@ -271,6 +272,37 @@ private void UpdateHeaderVisibility()
}
}

public
#if __IOS__ || __MACOS__
new
#endif
object Description
{
get => this.GetValue(DescriptionProperty);
set => this.SetValue(DescriptionProperty, value);
}

public static DependencyProperty DescriptionProperty { get; } =
DependencyProperty.Register(
nameof(Description), typeof(object),
typeof(ComboBox),
new FrameworkPropertyMetadata(default(object), propertyChangedCallback: (s, e) => (s as ComboBox)?.UpdateDescriptionVisibility(false)));

private void UpdateDescriptionVisibility(bool initialization)
{
if (initialization && Description == null)
{
// Avoid loading DescriptionPresenter element in template if not needed.
return;
}

var descriptionPresenter = this.FindName("DescriptionPresenter") as ContentPresenter;
if (descriptionPresenter != null)
{
descriptionPresenter.Visibility = Description != null ? Visibility.Visible : Visibility.Collapsed;
}
}

internal override void OnSelectedItemChanged(object oldSelectedItem, object selectedItem, bool updateItemSelectedState)
{
if (oldSelectedItem is _View view)
Expand Down
28 changes: 28 additions & 0 deletions src/Uno.UI/UI/Xaml/Controls/PasswordBox/PasswordBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ private protected override void OnLoaded()
{
base.OnLoaded();
RegisterSetPasswordScope();
UpdateDescriptionVisibility(true);
}

private void RegisterSetPasswordScope()
Expand Down Expand Up @@ -122,6 +123,18 @@ private void OnPasswordChanged(DependencyPropertyChangedEventArgs e)

#endregion

public new object Description
{
get => this.GetValue(DescriptionProperty);
set => this.SetValue(DescriptionProperty, value);
}

public static new global::Windows.UI.Xaml.DependencyProperty DescriptionProperty { get; } =
Windows.UI.Xaml.DependencyProperty.Register(
nameof(Description), typeof(object),
typeof(global::Windows.UI.Xaml.Controls.PasswordBox),
new FrameworkPropertyMetadata(default(object), propertyChangedCallback: (s, e) => (s as PasswordBox)?.UpdateDescriptionVisibility(false)));

protected override void OnTextChanged(DependencyPropertyChangedEventArgs e)
{
base.OnTextChanged(e);
Expand Down Expand Up @@ -256,5 +269,20 @@ private void OnFocusStateChanged(FocusState oldValue, FocusState newValue)
}
}
}

private void UpdateDescriptionVisibility(bool initialization)
{
if (initialization && Description == null)
{
// Avoid loading DescriptionPresenter element in template if not needed.
return;
}

var descriptionPresenter = this.FindName("DescriptionPresenter") as ContentPresenter;
if (descriptionPresenter != null)
{
descriptionPresenter.Visibility = Description != null ? Visibility.Visible : Visibility.Collapsed;
}
}
}
}
39 changes: 14 additions & 25 deletions src/Uno.UI/UI/Xaml/Controls/TextBox/TextBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ private void InitializeProperties()
OnFocusStateChanged((FocusState)FocusStateProperty.GetMetadata(GetType()).DefaultValue, FocusState, initial: true);
OnVerticalContentAlignmentChanged(VerticalAlignment.Top, VerticalContentAlignment);
OnTextCharacterCasingChanged(CreateInitialValueChangerEventArgs(CharacterCasingProperty, CharacterCasingProperty.GetMetadata(GetType()).DefaultValue, CharacterCasing));
OnDescriptionChanged(CreateInitialValueChangerEventArgs(DescriptionProperty, DescriptionProperty.GetMetadata(GetType()).DefaultValue, Description));
UpdateDescriptionVisibility(true);
var buttonRef = _deleteButton?.GetTarget();

if (buttonRef != null)
Expand Down Expand Up @@ -313,44 +313,33 @@ private object CoerceText(object baseValue)
#endif
object Description
{
get => (object)this.GetValue(DescriptionProperty);
set
{
this.SetValue(DescriptionProperty, value);
}
get => this.GetValue(DescriptionProperty);
set => this.SetValue(DescriptionProperty, value);
}

public static DependencyProperty DescriptionProperty { get; } =
DependencyProperty.Register(
"Description",
nameof(Description),
typeof(object),
typeof(TextBox),
new FrameworkPropertyMetadata(
defaultValue: null,
propertyChangedCallback: (s, e) => ((TextBox)s)?.OnDescriptionChanged(e)
propertyChangedCallback: (s, e) => ((TextBox)s)?.UpdateDescriptionVisibility(false)
)
);

private void OnDescriptionChanged(DependencyPropertyChangedEventArgs args)
private void UpdateDescriptionVisibility(bool initialization)
{
ContentPresenter descriptionPresenter = this.FindName("DescriptionPresenter") as ContentPresenter;
if (initialization && Description == null)
{
// Avoid loading DescriptionPresenter element in template if not needed.
return;
}

var descriptionPresenter = this.FindName("DescriptionPresenter") as ContentPresenter;
if (descriptionPresenter != null)
{
if (args.NewValue != null)
{
if (args.NewValue is string s && string.IsNullOrWhiteSpace(s))
{
descriptionPresenter.Visibility = Visibility.Collapsed;
}
else
{
descriptionPresenter.Visibility = Visibility.Visible;
}
}
else
{
descriptionPresenter.Visibility = Visibility.Collapsed;
}
descriptionPresenter.Visibility = Description != null ? Visibility.Visible : Visibility.Collapsed;
}
}
#endregion
Expand Down
Loading

0 comments on commit 46e0956

Please sign in to comment.