Skip to content

Commit

Permalink
fix(combobox): PlaceholderText not displaying
Browse files Browse the repository at this point in the history
  • Loading branch information
Xiaoy312 committed Aug 21, 2020
1 parent 8ef6ac4 commit 63a6d15
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/Uno.UI/UI/Xaml/Controls/ComboBox/ComboBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public partial class ComboBox : ListViewBase // TODO: Selector
private IPopup _popup;
private Border _popupBorder;
private ContentPresenter _contentPresenter;
private TextBlock _placeholderTextBlock;
private ContentPresenter _headerContentPresenter;

/// <summary>
Expand Down Expand Up @@ -79,6 +80,7 @@ protected override void OnApplyTemplate()
_popup = this.GetTemplateChild("Popup") as IPopup;
_popupBorder = this.GetTemplateChild("PopupBorder") as Border;
_contentPresenter = this.GetTemplateChild("ContentPresenter") as ContentPresenter;
_placeholderTextBlock = this.GetTemplateChild("PlaceholderTextBlock") as TextBlock;

if (_popup is PopupBase popup)
{
Expand All @@ -93,6 +95,8 @@ protected override void OnApplyTemplate()

if (_contentPresenter != null)
{
_contentPresenter.SynchronizeContentWithOuterTemplatedParent = false;

_contentPresenter.SetBinding(
ContentPresenter.ContentTemplateProperty,
new Binding(new PropertyPath("ItemTemplate"), null)
Expand Down Expand Up @@ -272,7 +276,7 @@ private void UpdateContentPresenter()
_selectionParentInDropdown = null;
}

_contentPresenter.Content = item;
_contentPresenter.Content = item ?? _placeholderTextBlock;

if (itemView != null && itemView.GetVisualTreeParent() != _contentPresenter)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ private void InitializeContentPresenter()
{
}

/// <summary>
/// Indicates if the content should inherit templated parent from the presenter, or its templated parent.
/// </summary>
/// <remarks>Clear this flag to let the control nested directly under this ContentPresenter to inherit the correct templated parent</remarks>
internal bool SynchronizeContentWithOuterTemplatedParent { get; set; } = true;

/// <summary>
/// Determines if the current ContentPresenter is hosting a native control.
/// </summary>
Expand Down Expand Up @@ -697,7 +703,9 @@ private void SynchronizeContentTemplatedParent()
{
var templatedParent = _contentTemplateRoot is ImplicitTextBlock
? this // ImplicitTextBlock is a special case that requires its TemplatedParent to be the ContentPresenter
: (this.TemplatedParent as IFrameworkElement)?.TemplatedParent;
: !SynchronizeContentWithOuterTemplatedParent && _dataTemplateUsedLastUpdate == null
? this.TemplatedParent
: (this.TemplatedParent as IFrameworkElement)?.TemplatedParent;

binder.TemplatedParent = templatedParent;
}
Expand Down

0 comments on commit 63a6d15

Please sign in to comment.