Skip to content

Commit

Permalink
propagate
Browse files Browse the repository at this point in the history
  • Loading branch information
PureWeen committed Nov 22, 2024
1 parent f642447 commit 9fe9f53
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<Import Condition="'$(EnvironmentBuildPropsImported)' != 'True'" Project="$(MSBuildThisFileDirectory)eng\Environment.Build.props" />

<PropertyGroup>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
<DebugType>portable</DebugType>
<DebugSymbols>true</DebugSymbols>
<LangVersion>Latest</LangVersion>
Expand Down
1 change: 1 addition & 0 deletions src/Controls/src/Core/ContentPresenter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ internal override void ComputeConstraintForView(View view)

internal override void SetChildInheritedBindingContext(Element child, object context)
{
base.SetChildInheritedBindingContext(child, context);
// We never want to use the standard inheritance mechanism, we will get this set by our parent
}

Expand Down
29 changes: 17 additions & 12 deletions src/Controls/src/Core/ContentView/ContentView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,20 @@ protected override void OnBindingContextChanged()
{
base.OnBindingContextChanged();

IView content = Content;
//IView content = Content;

if (content == null && (this as IContentView)?.PresentedContent is IView presentedContent)
content = presentedContent;
//if (content == null && (this as IContentView)?.PresentedContent is IView presentedContent)
// content = presentedContent;

ControlTemplate controlTemplate = ControlTemplate;
//ControlTemplate controlTemplate = ControlTemplate;

if (content is BindableObject bindableContent && controlTemplate != null)
SetInheritedBindingContext(bindableContent, BindingContext);
//if (content is BindableObject bindableContent && controlTemplate != null)
// SetInheritedBindingContext(bindableContent, BindingContext);
}

internal override void SetChildInheritedBindingContext(Element child, object context)
{
SetInheritedBindingContext(child, context);
}

internal override void OnControlTemplateChanged(ControlTemplate oldValue, ControlTemplate newValue)
Expand All @@ -39,12 +44,12 @@ internal override void OnControlTemplateChanged(ControlTemplate oldValue, Contro
return;

base.OnControlTemplateChanged(oldValue, newValue);
View content = Content;
ControlTemplate controlTemplate = ControlTemplate;
if (content != null && controlTemplate != null)
{
SetInheritedBindingContext(content, BindingContext);
}
//View content = Content;
//ControlTemplate controlTemplate = ControlTemplate;
//if (content != null && controlTemplate != null)
//{
// SetInheritedBindingContext(content, BindingContext);
//}
}

object IContentView.Content => Content;
Expand Down
31 changes: 30 additions & 1 deletion src/Controls/tests/Core.UnitTests/ContentViewUnitTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ public void ContentDoesGetBindingContext()
}

[Fact]
public void ContentParentIsNotInsideTempalte()
public void ContentParentIsNotInsideTemplate()
{
var contentView = new ContentView();
var child = new View();
Expand Down Expand Up @@ -384,5 +384,34 @@ public void ContentView_should_have_the_InternalChildren_correctly_when_Content_
Assert.Single(internalChildren);
Assert.Same(expected, internalChildren[0]);
}


[Fact]
public void BindingContextNotLost()
{
var bc = new object();
var contentView = new ContentView()
{
};


contentView.ControlTemplate = new ControlTemplate(typeof(SimpleTemplate));

var simpleTemplate1 = contentView.GetVisualTreeDescendants().OfType<SimpleTemplate>().Single();
contentView.Content = new Label();

contentView.BindingContext = bc;

var asdf = contentView.Content.BindingContext;

Assert.Same(bc, simpleTemplate1.BindingContext);

contentView.ControlTemplate = new ControlTemplate(typeof(SimpleTemplate));

var simpleTemplate2 = contentView.GetVisualTreeDescendants().OfType<SimpleTemplate>().Single();

Assert.NotSame(simpleTemplate1, simpleTemplate2);
Assert.Same(bc, simpleTemplate2.BindingContext);
}
}
}

0 comments on commit 9fe9f53

Please sign in to comment.