Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ReactiveUI.Tests/ReactiveUI.Tests_Net45.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@
<Compile Include="Winforms\ReactiveBindingListTests.cs" />
<Compile Include="Winforms\RoutedViewHostTests.cs" />
<Compile Include="Winforms\ViewModelViewHostTests.cs" />
<Compile Include="Xaml\ActivationForViewFetcherTest.cs" />
<Compile Include="Xaml\DependencyObjectObservableForPropertyTest.cs" />
<Compile Include="ErrorsTest.cs" />
<Compile Include="MessageBusTest.cs" />
Expand Down
132 changes: 132 additions & 0 deletions ReactiveUI.Tests/Xaml/ActivationForViewFetcherTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using Xunit;

namespace ReactiveUI.Tests
{
public class ActivationForViewFetcherTest
{
public class TestUserControl : UserControl, IActivatable
{
public TestUserControl()
{

}
}

[Fact]
public void FrameworkElementIsActivatedAndDeactivated()
{
var uc = new TestUserControl();
var activation = new ActivationForViewFetcher();

var obs = activation.GetActivationForView(uc);
var activated = obs.CreateCollection();

RoutedEventArgs loaded = new RoutedEventArgs();
loaded.RoutedEvent = FrameworkElement.LoadedEvent;

uc.RaiseEvent(loaded);

new[] { true }.AssertAreEqual(activated);

RoutedEventArgs unloaded = new RoutedEventArgs();
unloaded.RoutedEvent = FrameworkElement.UnloadedEvent;

uc.RaiseEvent(unloaded);

new[] { true, false }.AssertAreEqual(activated);
}

[Fact]
public void IsHitTestVisibleActivatesFrameworkElement()
{
var uc = new TestUserControl();
uc.IsHitTestVisible = false;
var activation = new ActivationForViewFetcher();

var obs = activation.GetActivationForView(uc);
var activated = obs.CreateCollection();

RoutedEventArgs loaded = new RoutedEventArgs();
loaded.RoutedEvent = FrameworkElement.LoadedEvent;

uc.RaiseEvent(loaded);

// IsHitTestVisible still false
new bool[0].AssertAreEqual(activated);

uc.IsHitTestVisible = true;

// IsHitTestVisible true
new[] { true }.AssertAreEqual(activated);

RoutedEventArgs unloaded = new RoutedEventArgs();
unloaded.RoutedEvent = FrameworkElement.UnloadedEvent;

uc.RaiseEvent(unloaded);

new[] { true, false }.AssertAreEqual(activated);
}

[Fact]
public void IsHitTestVisibleDeactivatesFrameworkElement()
{
var uc = new TestUserControl();
var activation = new ActivationForViewFetcher();

var obs = activation.GetActivationForView(uc);
var activated = obs.CreateCollection();

RoutedEventArgs loaded = new RoutedEventArgs();
loaded.RoutedEvent = FrameworkElement.LoadedEvent;

uc.RaiseEvent(loaded);

new[] { true }.AssertAreEqual(activated);

uc.IsHitTestVisible = false;

new[] { true, false }.AssertAreEqual(activated);
}

[Fact]
public void FrameworkElementIsActivatedAndDeactivatedWithHitTest()
{
var uc = new TestUserControl();
var activation = new ActivationForViewFetcher();

var obs = activation.GetActivationForView(uc);
var activated = obs.CreateCollection();

RoutedEventArgs loaded = new RoutedEventArgs();
loaded.RoutedEvent = FrameworkElement.LoadedEvent;

uc.RaiseEvent(loaded);

new[] { true }.AssertAreEqual(activated);

// this should deactivate it
uc.IsHitTestVisible = false;

new[] { true, false }.AssertAreEqual(activated);

// this should activate it
uc.IsHitTestVisible = true;

new[] { true, false, true }.AssertAreEqual(activated);

RoutedEventArgs unloaded = new RoutedEventArgs();
unloaded.RoutedEvent = FrameworkElement.UnloadedEvent;

uc.RaiseEvent(unloaded);

new[] { true, false, true, false }.AssertAreEqual(activated);
}
}
}
2 changes: 1 addition & 1 deletion ReactiveUI/Xaml/ActivationForViewFetcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public IObservable<bool> GetActivationForView(IActivatable view)

return viewLoaded
.Merge(viewUnloaded)
.Select(b => b ? fe.WhenAnyValue(x => x.IsHitTestVisible).Where(hv => hv && b) : Observable.Empty<bool>())
.Select(b => b ? fe.WhenAnyValue(x => x.IsHitTestVisible).Select(hv => hv && b).SkipWhile(x => !x) : Observable.Return(b))
.Switch()
.DistinctUntilChanged();
}
Expand Down