Browse Source
Merge pull request #1317 from AvaloniaUI/fixes/1182
Fix propogating resource changes to parented (but not children'd) nodes.
pull/1323/head
Jeremy Koritzinsky
9 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with
60 additions and
9 deletions
-
src/Avalonia.Controls/Control.cs
-
src/Avalonia.Controls/Primitives/PopupRoot.cs
-
tests/Avalonia.Controls.UnitTests/ControlTests_Resources.cs
-
tests/Avalonia.Controls.UnitTests/Primitives/PopupRootTests.cs
-
tests/Avalonia.Controls.UnitTests/Primitives/PopupTests.cs
|
|
|
@ -487,11 +487,6 @@ namespace Avalonia.Controls |
|
|
|
void ILogical.NotifyResourcesChanged(ResourcesChangedEventArgs e) |
|
|
|
{ |
|
|
|
ResourcesChanged?.Invoke(this, new ResourcesChangedEventArgs()); |
|
|
|
|
|
|
|
foreach (var child in LogicalChildren) |
|
|
|
{ |
|
|
|
child.NotifyResourcesChanged(e); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/// <inheritdoc/>
|
|
|
|
@ -536,6 +531,15 @@ namespace Avalonia.Controls |
|
|
|
} |
|
|
|
|
|
|
|
_parent = (IControl)parent; |
|
|
|
|
|
|
|
if (old != null) |
|
|
|
{ |
|
|
|
old.ResourcesChanged -= ThisResourcesChanged; |
|
|
|
} |
|
|
|
if (_parent != null) |
|
|
|
{ |
|
|
|
_parent.ResourcesChanged += ThisResourcesChanged; |
|
|
|
} |
|
|
|
((ILogical)this).NotifyResourcesChanged(new ResourcesChangedEventArgs()); |
|
|
|
|
|
|
|
if (_parent is IStyleRoot || _parent?.IsAttachedToLogicalTree == true || this is IStyleRoot) |
|
|
|
|
|
|
|
@ -8,6 +8,7 @@ using Avalonia.Interactivity; |
|
|
|
using Avalonia.Layout; |
|
|
|
using Avalonia.Media; |
|
|
|
using Avalonia.Platform; |
|
|
|
using Avalonia.Styling; |
|
|
|
using Avalonia.VisualTree; |
|
|
|
using JetBrains.Annotations; |
|
|
|
|
|
|
|
@ -16,7 +17,7 @@ namespace Avalonia.Controls.Primitives |
|
|
|
/// <summary>
|
|
|
|
/// The root window of a <see cref="Popup"/>.
|
|
|
|
/// </summary>
|
|
|
|
public class PopupRoot : WindowBase, IInteractive, IHostedVisualTreeRoot, IDisposable |
|
|
|
public class PopupRoot : WindowBase, IInteractive, IHostedVisualTreeRoot, IDisposable, IStyleHost |
|
|
|
{ |
|
|
|
private IDisposable _presenterSubscription; |
|
|
|
|
|
|
|
@ -66,6 +67,11 @@ namespace Avalonia.Controls.Primitives |
|
|
|
/// </summary>
|
|
|
|
IVisual IHostedVisualTreeRoot.Host => Parent; |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gets the styling parent of the popup root.
|
|
|
|
/// </summary>
|
|
|
|
IStyleHost IStyleHost.StylingParent => Parent; |
|
|
|
|
|
|
|
/// <inheritdoc/>
|
|
|
|
public void Dispose() => PlatformImpl?.Dispose(); |
|
|
|
|
|
|
|
|
|
|
|
@ -168,7 +168,7 @@ namespace Avalonia.Controls.UnitTests |
|
|
|
target.Resources.Add("foo", "bar"); |
|
|
|
|
|
|
|
Assert.True(raisedOnTarget); |
|
|
|
Assert.False(raisedOnPresenter); |
|
|
|
Assert.True(raisedOnPresenter); |
|
|
|
Assert.True(raisedOnChild); |
|
|
|
} |
|
|
|
|
|
|
|
@ -204,6 +204,22 @@ namespace Avalonia.Controls.UnitTests |
|
|
|
Assert.True(raised); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void Setting_Logical_Parent_Subscribes_To_Parents_ResourceChanged_Event() |
|
|
|
{ |
|
|
|
var parent = new ContentControl(); |
|
|
|
var child = new Border(); |
|
|
|
|
|
|
|
((ISetLogicalParent)child).SetParent(parent); |
|
|
|
var raisedOnChild = false; |
|
|
|
|
|
|
|
child.ResourcesChanged += (_, __) => raisedOnChild = true; |
|
|
|
|
|
|
|
parent.Resources.Add("foo", "bar"); |
|
|
|
|
|
|
|
Assert.True(raisedOnChild); |
|
|
|
} |
|
|
|
|
|
|
|
private IControlTemplate ContentControlTemplate() |
|
|
|
{ |
|
|
|
return new FuncControlTemplate<ContentControl>(x => |
|
|
|
|
|
|
|
@ -7,6 +7,7 @@ using Avalonia.Controls.Presenters; |
|
|
|
using Avalonia.Controls.Primitives; |
|
|
|
using Avalonia.Controls.Templates; |
|
|
|
using Avalonia.LogicalTree; |
|
|
|
using Avalonia.Styling; |
|
|
|
using Avalonia.UnitTests; |
|
|
|
using Avalonia.VisualTree; |
|
|
|
using Xunit; |
|
|
|
@ -37,6 +38,25 @@ namespace Avalonia.Controls.UnitTests.Primitives |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void PopupRoot_StylingParent_Is_Popup() |
|
|
|
{ |
|
|
|
using (UnitTestApplication.Start(TestServices.StyledWindow)) |
|
|
|
{ |
|
|
|
var target = new TemplatedControlWithPopup |
|
|
|
{ |
|
|
|
PopupContent = new Canvas(), |
|
|
|
}; |
|
|
|
|
|
|
|
var root = new TestRoot { Child = target }; |
|
|
|
|
|
|
|
target.ApplyTemplate(); |
|
|
|
target.Popup.Open(); |
|
|
|
|
|
|
|
Assert.Equal(target.Popup, ((IStyleHost)target.Popup.PopupRoot).StylingParent); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void Attaching_PopupRoot_To_Parent_Logical_Tree_Raises_DetachedFromLogicalTree_And_AttachedToLogicalTree() |
|
|
|
{ |
|
|
|
|
|
|
|
@ -15,6 +15,7 @@ using Avalonia.Styling; |
|
|
|
using Avalonia.UnitTests; |
|
|
|
using Avalonia.VisualTree; |
|
|
|
using Xunit; |
|
|
|
using Avalonia.Input; |
|
|
|
|
|
|
|
namespace Avalonia.Controls.UnitTests.Primitives |
|
|
|
{ |
|
|
|
@ -189,9 +190,11 @@ namespace Avalonia.Controls.UnitTests.Primitives |
|
|
|
{ |
|
|
|
using (CreateServices()) |
|
|
|
{ |
|
|
|
var window = new Window(); |
|
|
|
var target = new Popup(); |
|
|
|
var child = new Control(); |
|
|
|
|
|
|
|
window.Content = target; |
|
|
|
target.Open(); |
|
|
|
|
|
|
|
Assert.Single(target.PopupRoot.GetVisualChildren()); |
|
|
|
@ -214,7 +217,8 @@ namespace Avalonia.Controls.UnitTests.Primitives |
|
|
|
{ |
|
|
|
Content = new Border(), |
|
|
|
Template = new FuncControlTemplate<PopupContentControl>(PopupContentControlTemplate), |
|
|
|
} |
|
|
|
}, |
|
|
|
StylingParent = AvaloniaLocator.Current.GetService<IGlobalStyles>() |
|
|
|
}; |
|
|
|
|
|
|
|
target.ApplyTemplate(); |
|
|
|
@ -306,7 +310,8 @@ namespace Avalonia.Controls.UnitTests.Primitives |
|
|
|
.Bind<IGlobalStyles>().ToFunc(() => globalStyles.Object) |
|
|
|
.Bind<IWindowingPlatform>().ToConstant(new WindowingPlatformMock()) |
|
|
|
.Bind<IStyler>().ToTransient<Styler>() |
|
|
|
.Bind<IPlatformRenderInterface>().ToFunc(() => renderInterface.Object); |
|
|
|
.Bind<IPlatformRenderInterface>().ToFunc(() => renderInterface.Object) |
|
|
|
.Bind<IInputManager>().ToConstant(new InputManager()); |
|
|
|
|
|
|
|
return result; |
|
|
|
} |
|
|
|
|