public void Get_Affinity_For_View_Should_Return_Non_Zero_For_Visual_Elements() { var userControl = new TestUserControl(); var activationForViewFetcher = new AvaloniaActivationForViewFetcher(); var forUserControl = activationForViewFetcher.GetAffinityForView(userControl.GetType()); var forNonUserControl = activationForViewFetcher.GetAffinityForView(typeof(object)); Assert.NotEqual(0, forUserControl); Assert.Equal(0, forNonUserControl); }
/// <summary> /// Registers the avalonia services. /// </summary> /// <param name="container">The container.</param> private void RegisterAvaloniaServices(Container container) { var viewFetcher = new AvaloniaActivationForViewFetcher(); var dataTemplate = new AutoDataTemplateBindingHook(); Locator.CurrentMutable.RegisterConstant(viewFetcher, typeof(IActivationForViewFetcher)); Locator.CurrentMutable.RegisterConstant(dataTemplate, typeof(IPropertyBindingHook)); container.RegisterInstance <IActivationForViewFetcher>(viewFetcher); container.RegisterInstance <IPropertyBindingHook>(dataTemplate); Avalonia.Logging.Logger.Sink = new AvaloniaLogger(); }
public void Visual_Element_Is_Activated_And_Deactivated() { var userControl = new TestUserControl(); var activationForViewFetcher = new AvaloniaActivationForViewFetcher(); activationForViewFetcher .GetActivationForView(userControl) .ToObservableChangeSet(scheduler: ImmediateScheduler.Instance) .Bind(out var activated) .Subscribe(); var fakeRenderedDecorator = new TestRoot(); fakeRenderedDecorator.Child = userControl; Assert.True(activated[0]); Assert.Equal(1, activated.Count); fakeRenderedDecorator.Child = null; Assert.True(activated[0]); Assert.False(activated[1]); Assert.Equal(2, activated.Count); }