Skip to content

Commit

Permalink
chore(combobox): restored content assignment timing
Browse files Browse the repository at this point in the history
  • Loading branch information
Xiaoy312 committed Aug 24, 2020
1 parent 894eaf4 commit 3870dd8
Showing 1 changed file with 36 additions and 36 deletions.
72 changes: 36 additions & 36 deletions src/Uno.UI/UI/Xaml/Controls/ComboBox/ComboBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -241,54 +241,54 @@ internal override void OnItemClicked(int clickedIndex)

private void UpdateContentPresenter()
{
if (_contentPresenter != null)
if (_contentPresenter == null) return;

if (SelectedItem != null)
{
if (SelectedItem != null)
var item = GetSelectionContent();
var itemView = item as _View;

if (itemView != null)
{
var item = GetSelectionContent();
if (item is _View itemView)
{
#if __ANDROID__
var comboBoxItem = itemView.FindFirstParentOfView<ComboBoxItem>();
var comboBoxItem = itemView.FindFirstParentOfView<ComboBoxItem>();
#else
var comboBoxItem = itemView.FindFirstParent<ComboBoxItem>();
var comboBoxItem = itemView.FindFirstParent<ComboBoxItem>();
#endif
if (comboBoxItem != null)
{
// Keep track of the former parent, so we can put the item back when the dropdown is shown
_selectionParentInDropdown = (itemView.GetVisualTreeParent() as IWeakReferenceProvider)?.WeakReference;
}

if (itemView.GetVisualTreeParent() != _contentPresenter)
{
// Item may have been put back in list, reattach it to _contentPresenter
_contentPresenter.AddChild(itemView);
}
}
else
if (comboBoxItem != null)
{
_selectionParentInDropdown = null;
// Keep track of the former parent, so we can put the item back when the dropdown is shown
_selectionParentInDropdown = (itemView.GetVisualTreeParent() as IWeakReferenceProvider)?.WeakReference;
}
}
else
{
_selectionParentInDropdown = null;
}

_contentPresenter.Content = item ?? _placeholderTextBlock;
if (!_areItemTemplatesForwarded)
{
SetContentPresenterBinding(ContentPresenter.ContentTemplateProperty, nameof(ItemTemplate));
SetContentPresenterBinding(ContentPresenter.ContentTemplateSelectorProperty, nameof(ItemTemplateSelector));
_contentPresenter.Content = item;
if (itemView != null && itemView.GetVisualTreeParent() != _contentPresenter)
{
// Item may have been put back in list, reattach it to _contentPresenter
_contentPresenter.AddChild(itemView);
}
if (!_areItemTemplatesForwarded)
{
SetContentPresenterBinding(ContentPresenter.ContentTemplateProperty, nameof(ItemTemplate));
SetContentPresenterBinding(ContentPresenter.ContentTemplateSelectorProperty, nameof(ItemTemplateSelector));

_areItemTemplatesForwarded = true;
}
_areItemTemplatesForwarded = true;
}
else
}
else
{
_contentPresenter.Content = _placeholderTextBlock;
if (_areItemTemplatesForwarded)
{
_contentPresenter.Content = _placeholderTextBlock;
if (_areItemTemplatesForwarded)
{
_contentPresenter.ClearValue(ContentPresenter.ContentTemplateProperty);
_contentPresenter.ClearValue(ContentPresenter.ContentTemplateSelectorProperty);
_contentPresenter.ClearValue(ContentPresenter.ContentTemplateProperty);
_contentPresenter.ClearValue(ContentPresenter.ContentTemplateSelectorProperty);

_areItemTemplatesForwarded = false;
}
_areItemTemplatesForwarded = false;
}
}

Expand Down

0 comments on commit 3870dd8

Please sign in to comment.