14 changed files with 313 additions and 31 deletions
@ -0,0 +1,83 @@ |
|||
// Copyright (c) The Perspex Project. All rights reserved.
|
|||
// Licensed under the MIT license. See licence.md file in the project root for full license information.
|
|||
|
|||
using Perspex.Controls; |
|||
using Perspex.Markup.Xaml.Data; |
|||
using Xunit; |
|||
|
|||
namespace Perspex.Markup.Xaml.UnitTests.Data |
|||
{ |
|||
public class BindingTests_ElementName |
|||
{ |
|||
[Fact] |
|||
public void Should_Bind_To_Element() |
|||
{ |
|||
TextBlock target; |
|||
var root = new TestRoot |
|||
{ |
|||
Child = new StackPanel |
|||
{ |
|||
Children = new Controls.Controls |
|||
{ |
|||
new TextBlock |
|||
{ |
|||
Name = "source", |
|||
Text = "foo", |
|||
}, |
|||
(target = new TextBlock |
|||
{ |
|||
Name = "target", |
|||
}) |
|||
} |
|||
} |
|||
}; |
|||
|
|||
var binding = new Binding |
|||
{ |
|||
ElementName = "source", |
|||
SourcePropertyPath = "Text", |
|||
}; |
|||
|
|||
binding.Bind(target, TextBlock.TextProperty); |
|||
|
|||
Assert.Equal("foo", target.Text); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Should_Bind_To_Later_Added_Element() |
|||
{ |
|||
TextBlock target; |
|||
StackPanel stackPanel; |
|||
|
|||
var root = new TestRoot |
|||
{ |
|||
Child = stackPanel = new StackPanel |
|||
{ |
|||
Children = new Controls.Controls |
|||
{ |
|||
(target = new TextBlock |
|||
{ |
|||
Name = "target", |
|||
}), |
|||
} |
|||
} |
|||
}; |
|||
|
|||
var binding = new Binding |
|||
{ |
|||
ElementName = "source", |
|||
SourcePropertyPath = "Text", |
|||
}; |
|||
|
|||
binding.Bind(target, TextBlock.TextProperty); |
|||
|
|||
stackPanel.Children.Add(new TextBlock |
|||
{ |
|||
Name = "source", |
|||
Text = "foo", |
|||
}); |
|||
|
|||
Assert.Equal("foo", target.Text); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,61 @@ |
|||
// Copyright (c) The Perspex Project. All rights reserved.
|
|||
// Licensed under the MIT license. See licence.md file in the project root for full license information.
|
|||
|
|||
using System; |
|||
using Perspex.Controls; |
|||
using Perspex.Platform; |
|||
using Perspex.Rendering; |
|||
|
|||
namespace Perspex.Markup.Xaml.UnitTests |
|||
{ |
|||
public class TestRoot : Decorator, IRenderRoot, INameScope |
|||
{ |
|||
private readonly NameScope _nameScope = new NameScope(); |
|||
|
|||
event EventHandler<NameScopeEventArgs> INameScope.Registered |
|||
{ |
|||
add { _nameScope.Registered += value; ++NameScopeRegisteredSubscribers; } |
|||
remove { _nameScope.Registered -= value; --NameScopeRegisteredSubscribers; } |
|||
} |
|||
|
|||
public event EventHandler<NameScopeEventArgs> Unregistered |
|||
{ |
|||
add { _nameScope.Unregistered += value; ++NameScopeUnregisteredSubscribers; } |
|||
remove { _nameScope.Unregistered -= value; --NameScopeUnregisteredSubscribers; } |
|||
} |
|||
|
|||
public int NameScopeRegisteredSubscribers { get; private set; } |
|||
|
|||
public int NameScopeUnregisteredSubscribers { get; private set; } |
|||
|
|||
public IRenderTarget RenderTarget |
|||
{ |
|||
get { throw new NotImplementedException(); } |
|||
} |
|||
|
|||
public IRenderQueueManager RenderQueueManager |
|||
{ |
|||
get { throw new NotImplementedException(); } |
|||
} |
|||
|
|||
public Point TranslatePointToScreen(Point p) |
|||
{ |
|||
throw new NotImplementedException(); |
|||
} |
|||
|
|||
public void Register(string name, object element) |
|||
{ |
|||
_nameScope.Register(name, element); |
|||
} |
|||
|
|||
public object Find(string name) |
|||
{ |
|||
return _nameScope.Find(name); |
|||
} |
|||
|
|||
public void Unregister(string name) |
|||
{ |
|||
_nameScope.Unregister(name); |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue