зеркало из https://github.com/DeGsoft/maui-linux.git
[Shell] propagate BindingContext to SearchHandler (#5730)
- fixes #5705
This commit is contained in:
Родитель
abd3f350de
Коммит
3f65849d76
|
@ -199,6 +199,9 @@ namespace Xamarin.Forms
|
|||
BindingContextChanged?.Invoke(this, EventArgs.Empty);
|
||||
if (Shell.GetBackButtonBehavior(this) is BackButtonBehavior buttonBehavior)
|
||||
SetInheritedBindingContext(buttonBehavior, BindingContext);
|
||||
|
||||
if (Shell.GetSearchHandler(this) is SearchHandler searchHandler)
|
||||
SetInheritedBindingContext(searchHandler, BindingContext);
|
||||
}
|
||||
|
||||
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
|
||||
|
|
|
@ -35,7 +35,16 @@ namespace Xamarin.Forms
|
|||
BindableProperty.CreateAttached("NavBarIsVisible", typeof(bool), typeof(Shell), true);
|
||||
|
||||
public static readonly BindableProperty SearchHandlerProperty =
|
||||
BindableProperty.CreateAttached("SearchHandler", typeof(SearchHandler), typeof(Shell), null, BindingMode.OneTime);
|
||||
BindableProperty.CreateAttached("SearchHandler", typeof(SearchHandler), typeof(Shell), null, BindingMode.OneTime,
|
||||
propertyChanged: OnSearchHandlerPropertyChanged);
|
||||
|
||||
static void OnSearchHandlerPropertyChanged(BindableObject bindable, object oldValue, object newValue)
|
||||
{
|
||||
if (oldValue is SearchHandler oldHandler)
|
||||
SetInheritedBindingContext(oldHandler, null);
|
||||
if (newValue is SearchHandler newHandler)
|
||||
SetInheritedBindingContext(newHandler, bindable.BindingContext);
|
||||
}
|
||||
|
||||
public static readonly BindableProperty SetPaddingInsetsProperty =
|
||||
BindableProperty.CreateAttached("SetPaddingInsets", typeof(bool), typeof(Shell), false);
|
||||
|
@ -1069,14 +1078,11 @@ namespace Xamarin.Forms
|
|||
return element;
|
||||
}
|
||||
|
||||
|
||||
#region IPropertyPropagationController
|
||||
void IPropertyPropagationController.PropagatePropertyChanged(string propertyName)
|
||||
{
|
||||
PropertyPropagationExtensions.PropagatePropertyChanged(propertyName, this, LogicalChildren);
|
||||
if (FlyoutHeaderView != null)
|
||||
PropertyPropagationExtensions.PropagatePropertyChanged(propertyName, this, new[] { FlyoutHeaderView });
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Shell xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="Xamarin.Forms.Xaml.UnitTests.Gh5705">
|
||||
<Shell.SearchHandler>
|
||||
<SearchHandler x:Name="searchHandler"/>
|
||||
</Shell.SearchHandler>
|
||||
</Shell>
|
|
@ -0,0 +1,45 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using NUnit.Framework;
|
||||
using Xamarin.Forms;
|
||||
using Xamarin.Forms.Core.UnitTests;
|
||||
|
||||
namespace Xamarin.Forms.Xaml.UnitTests
|
||||
{
|
||||
public partial class Gh5705 : Shell
|
||||
{
|
||||
public Gh5705() => InitializeComponent();
|
||||
public Gh5705(bool useCompiledXaml)
|
||||
{
|
||||
//this stub will be replaced at compile time
|
||||
}
|
||||
|
||||
[TestFixture] class Tests
|
||||
{
|
||||
IReadOnlyList<string> _flags;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
Device.PlatformServices = new MockPlatformServices();
|
||||
_flags = Device.Flags;
|
||||
Device.SetFlags(new List<string>() { ExperimentalFlags.ShellExperimental});
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown()
|
||||
{
|
||||
Device.PlatformServices = null;
|
||||
Device.SetFlags(_flags);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SearchHandlerIneritBC([Values(false, true)]bool useCompiledXaml)
|
||||
{
|
||||
var vm = new object();
|
||||
var shell = new Gh5705(useCompiledXaml) { BindingContext = vm };
|
||||
Assert.That(shell.searchHandler.BindingContext, Is.EqualTo(vm));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Загрузка…
Ссылка в новой задаче