Xamarin形成Bind到ColumnDefinition Width属性

时间:2017-05-03 23:37:33

标签: xamarin grid xamarin.forms

我正在尝试绑定列定义的widthproperty,但似乎无法获取绑定。谁能告诉我如何将Xamarin Grid列定义绑定到属性?

自定义类中的绑定属性:

public static readonly BindableProperty PointsColumnsProperty = BindableProperty.Create(nameof(PointsBarColumns), typeof(ColumnDefinitionCollection), typeof(RewardsPanel), new ColumnDefinitionCollection());

这是我的财产:

public GridLength PointsFill {
    get => (GridLength)GetValue(PointsFillProperty);
    set => SetValue(PointsFillProperty, value);
}

这就是我设置绑定的方式:

_pointsBar.ColumnDefinitions[0].SetBinding(ColumnDefinition.WidthProperty, nameof(PointsFill));

1 个答案:

答案 0 :(得分:0)

我错过了_pointsBar上的绑定上下文。

        _pointsBar = new Grid
        {
            BackgroundColor   = BasicStyle.PrimaryColor,
            Style             = BasicStyle.PointsAndVisits, BindingContext = this,
            ColumnDefinitions =
            {
                new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) },
                new ColumnDefinition { Width = new GridLength(100, GridUnitType.Star) }
            }
        };
相关问题