Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/xamarin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Data binding 在Xamarin.Forms中更改属性时,不会更新SearchBar.IsEnabled绑定_Data Binding_Xamarin_Searchbar_Xamarin.forms - Fatal编程技术网

Data binding 在Xamarin.Forms中更改属性时,不会更新SearchBar.IsEnabled绑定

Data binding 在Xamarin.Forms中更改属性时,不会更新SearchBar.IsEnabled绑定,data-binding,xamarin,searchbar,xamarin.forms,Data Binding,Xamarin,Searchbar,Xamarin.forms,我想在viewmodel忙时禁用搜索栏。 我的视图有以下xaml(视图的一部分): 这两个元素都绑定到同一属性,但是当my ViewModel raise IsBusy=false时,搜索栏将保持禁用状态。同时,进步也被隐藏了起来 这里可能有什么问题?您想要的是设置搜索栏。当您查看模型IsBusy时,IsEnabled属性为true,反之亦然 您现在正在做的是,当您的vie模型不再忙时(IsBusy为false),禁用搜索栏(将isnabled设置为false) 为此,您需要一个转换器,该转

我想在viewmodel忙时禁用搜索栏。 我的视图有以下xaml(视图的一部分):


这两个元素都绑定到同一属性,但是当my ViewModel raise IsBusy=false时,搜索栏将保持禁用状态。同时,进步也被隐藏了起来


这里可能有什么问题?

您想要的是设置
搜索栏。当您查看模型
IsBusy时,IsEnabled
属性为
true
,反之亦然

您现在正在做的是,当您的vie模型不再忙时(
IsBusy
为false),禁用搜索栏(将
isnabled
设置为false)

为此,您需要一个转换器,该转换器返回true表示false,返回false表示true:

公共类NotConverter:IValueConverter
{
公共对象转换(对象值、类型targetType、对象参数、System.Globalization.CultureInfo区域性)
{
if(value.GetType()==typeof(bool))
返回!((bool)值);
返回值;
}
公共对象转换回(对象值、类型targetType、对象参数、System.Globalization.CultureInfo区域性)
{
抛出新的NotImplementedException();
}
}
为了在xaml中的绑定中使用它,让我们在包装xaml片段的容器中包含它的一个实例作为资源(假设它是
ContentPage
),然后我们可以在
{binding}
标记扩展中引用该转换器:


您想要的是设置
搜索栏。当您查看模型
IsBusy时,IsEnabled
属性为
true
,反之亦然

您现在正在做的是,当您的vie模型不再忙时(
IsBusy
为false),禁用搜索栏(将
isnabled
设置为false)

为此,您需要一个转换器,该转换器返回true表示false,返回false表示true:

公共类NotConverter:IValueConverter
{
公共对象转换(对象值、类型targetType、对象参数、System.Globalization.CultureInfo区域性)
{
if(value.GetType()==typeof(bool))
返回!((bool)值);
返回值;
}
公共对象转换回(对象值、类型targetType、对象参数、System.Globalization.CultureInfo区域性)
{
抛出新的NotImplementedException();
}
}
为了在xaml中的绑定中使用它,让我们在包装xaml片段的容器中包含它的一个实例作为资源(假设它是
ContentPage
),然后我们可以在
{binding}
标记扩展中引用该转换器: