2017-05-03 6 views
0

Ich versuche, die widthproperty einer Spaltendefinition zu binden, aber kann nicht scheinen, um die Bindung zu erhalten. Kann mir jemand sagen, wie man an eine Xamarin Grid-Spaltendefinition an eine Eigenschaft bindet?Xamarin Forms Bindung an ColumnDefinition Width Eigenschaft

Bindungseigenschaft in benutzerdefinierten Klasse:

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

Das ist mein Eigentum:

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

Dies ist, wie ich die Bindung setze:

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

Antwort

0

mir fehlte die Bindung Kontext auf der _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) } 
      } 
     }; 
Verwandte Themen