本文介绍了可见性绑定失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试将Visibility插件与FieldBinding插件结合使用时没有运气.

I try to use the Visibility plugin with the FieldBinding plugin with no luck.

模型侧:

    /// <summary>
    /// Gets or sets the birthdate.
    /// </summary>
    /// <value>
    /// The birthdate.
    /// </value>
    public DateTime? Birthdate { get; set; }

ViewModel端:

ViewModel side:

public class DisplayUserViewModel : BaseUserViewModel
{
    /// <summary>
    /// The user
    /// </summary>
    public readonly INC<User> User = new NC<User>();
}

从侧面看,首先尝试:

        <RelativeLayout
            android:layout_width="wrap_content"
            android:layout_height="@dimen/ListIconTwoLineTileHeight"
            android:paddingRight="@dimen/ListIconTwoLineTextMarginRight"
            local:MvxBind="Visibility User.Birthdate, Converter=Visibility">

第二次尝试:

        <RelativeLayout
            android:layout_width="wrap_content"
            android:layout_height="@dimen/ListIconTwoLineTileHeight"
            android:paddingRight="@dimen/ListIconTwoLineTextMarginRight"
            local:MvxBind="Visibility Visibility(User.Birthdate)">

但结果相同:

MvxBind ( 2574):  33.60 Failed to create target binding for binding Visibility for MvxValueConverterValueCombiner combiner-operation

我只是以生日为例,但是每个可见性绑定都失败了(对于x绑定,我有x条错误消息).

I just took the birthdate as an example, but every Visibility bindings failed (I have x error messages for x bindings).

编辑1

其他绑定工作,我绑定了一堆文本,并且所有显示都很好:

The others binding work, I bind a bunch of text, and all display well:

      <TextView
         style="@style/TextView.ListWithIcon.Single"
         android:layout_marginTop="@dimen/ListIconTwoLineTextMarginTop"
         local:MvxBind="Text User.FirstName" />

我也尝试绑定到INPC属性,结果相同.

I also try to bind to a INPC property, same result.

编辑2

按照stuart的建议,我尝试了以下方法:

As suggested by stuart, i tried this:

<TextView
    style="@style/TextView.ListWithIcon.Single"
    android:layout_marginTop="@dimen/ListIconTwoLineTextMarginTop"
    android:layout_marginLeft="@dimen/ListIconTextMarginLeft"
    local:MvxBind="Text Visibility(User.Birthdate)">

如果Birthdate为null,则TextView上的可见性转换器似乎可以工作:

And the visibility converter on TextView seems to work, if Birthdate is null:

Birthdate:  Gone

但是它似乎没有绑定到visible属性:

But it does not seem to bind to the visibility property:

<TextView
    style="@style/TextView.ListWithIcon.SecondLine"
    android:layout_below="@+id/Birthday"
    local:MvxBind="Visibility Visibility(User.Birthdate)"
    android:text="Whatever birthdate" />

显示任何生日",而Visibility(User.Birthdate)返回消失" ...

Displays "Whatever birthdate" whereas Visibility(User.Birthdate) returns Gone...

编辑3

如果您使用可见伪属性,那么一切都会按预期进行.

If you use Visible pseudo-property everything works as expected.

<RelativeLayout
            android:layout_width="wrap_content"
            android:layout_height="@dimen/ListIconTwoLineTileHeight"
            android:paddingRight="@dimen/ListIconTwoLineTextMarginRight"
            local:MvxBind="Visible User.Birthdate">

推荐答案

我在LinearLayout中遇到了相同的问题:

I had the same issue with a LinearLayout:

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"
    android:orientation="vertical"
    android:background="@color/white"
    local:MvxBind="Visibility Visibility(IsLoading)">

LinearLayout的可见性不会绑定到我的视图模型:

Visibility of the LinearLayout wouldn't bind to my view model:

解决方案:在LinkerPleaseInclude.cs中添加一个条目,这样就不会从视图中剥离Visibility属性:

Solution: add an entry to LinkerPleaseInclude.cs so the Visibility property isn't stripped from the view:

public void Include(LinearLayout layout)
{
    layout.Click += (s, e) => layout.Visibility = layout.Visibility - 1;
}

这篇关于可见性绑定失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-25 13:16