Skip to content

Commit

Permalink
fix(contentcontrol): [macOS/iOS] Support binding DataContext in Conte…
Browse files Browse the repository at this point in the history
…ntTemplate
  • Loading branch information
davidjohnoliver committed Dec 15, 2020
1 parent 418fea3 commit c72c24e
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/Uno.UI/UI/Xaml/Controls/ContentControl/ContentControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public virtual object Content
set { SetValue(ContentProperty, value); }
}

public static DependencyProperty ContentProperty { get ; } =
public static DependencyProperty ContentProperty { get; } =
DependencyProperty.Register(
"Content",
typeof(object),
Expand All @@ -134,7 +134,7 @@ public DataTemplate ContentTemplate
}

// Using a DependencyProperty as the backing store for ContentTemplate. This enables animation, styling, binding, etc...
public static DependencyProperty ContentTemplateProperty { get ; } =
public static DependencyProperty ContentTemplateProperty { get; } =
DependencyProperty.Register(
"ContentTemplate",
typeof(DataTemplate),
Expand All @@ -155,7 +155,7 @@ public DataTemplateSelector ContentTemplateSelector
set { SetValue(ContentTemplateSelectorProperty, value); }
}

public static DependencyProperty ContentTemplateSelectorProperty { get ; } =
public static DependencyProperty ContentTemplateSelectorProperty { get; } =
DependencyProperty.Register(
"ContentTemplateSelector",
typeof(DataTemplateSelector),
Expand Down Expand Up @@ -272,7 +272,7 @@ public TransitionCollection ContentTransitions
set { this.SetValue(ContentTransitionsProperty, value); }
}

public static DependencyProperty ContentTransitionsProperty { get ; } =
public static DependencyProperty ContentTransitionsProperty { get; } =
DependencyProperty.Register("ContentTransitions", typeof(TransitionCollection), typeof(ContentControl), new FrameworkPropertyMetadata(null, OnContentTransitionsChanged));
#nullable enable

Expand Down Expand Up @@ -427,7 +427,10 @@ protected virtual void SyncDataContext()
}
else
{
if (ContentTemplateRoot is IDependencyObjectStoreProvider provider)
if ((ContentTemplateRoot is IDependencyObjectStoreProvider provider) &&
// The DataContext may be set directly on the template root
(_localContentDataContextOverride || !this.IsDependencyPropertySet(provider.Store.DataContextProperty))
)
{
_localContentDataContextOverride = true;
provider.Store.SetValue(provider.Store.DataContextProperty, Content, DependencyPropertyValuePrecedences.Local);
Expand Down

0 comments on commit c72c24e

Please sign in to comment.