Xamarin.Forms。自定义属性绑定问题

时间:2016-04-26 13:24:34

标签: xaml xamarin.forms

我在Xamarin中创建了自定义控件。其中之一是ValidatedEntryCell:

 public class ValidatedEntryCell: EntryCell
{
    public static readonly BindableProperty ShowBorderProperty = BindableProperty.Create(nameof(ShowBorder), typeof(bool), typeof(ValidatedEntryCell), false);
    public bool ShowBorder
    {
        get { return (bool)GetValue(ShowBorderProperty); }
        set
        {
            SetValue(ShowBorderProperty, value);
            OnPropertyChanged();
        }
    }
}

如果Text为空,我想更改ShowBorder属性。我尝试了几种情况如何调用该属性:

  • 在xaml中直接调用该属性。如:renderers:ValidatedPicker x:Name="Gender" Title="Gender" ShowBorder="True" 这种情况很好。
  • <renderers:ValidatedEntryCell ShowBorder="{Binding FirstNameIsNotValid}" x:Name="FirstName" ...(我在代码隐藏中设置FirstNameIsNotValid = true
  • 我使用的转化器<renderers:ValidatedEntryCell x:Name="LastName" ShowBorder="{Binding Source={x:Reference LastName}, Converter={StaticResource EmptyTextToBoolConverter}, Path=Text.Length}"始终返回true

尝试使用属性的样式触发器。 不幸的是,这里有什对任何建议都会很高兴

编辑:部分帮助link。现在我可以在代码隐藏中的构造函数中设置属性,并且可以看到所做的更改。

0 个答案:

没有答案
相关问题