Multiple bindingContext on same page

446 views Asked by At

I use listview with headerTemplate. I need to create a bindableproperty to add a Text to my Template.

so I create a bindable property in my headertemplate "MyMenuHeader":

public static readonly BindableProperty TitleTextproperty =
BindableProperty.Create("TitleText", typeof(String), typeof(MyMenuHeader), null);

public String TitleText
{
   get { return (String)GetValue(TitleTextproperty); }
   set {
         SetValue(TitleTextproperty, value);
         OnPropertyChanged("TitleText");
       }
}

var nomGroup = new Label
            {
                TextColor = Color.FromHex(ConstColor.PrimaryPrastel),
                HorizontalOptions = LayoutOptions.CenterAndExpand,
                FontSize = 15,
                HorizontalTextAlignment = TextAlignment.Start,
                VerticalOptions = LayoutOptions.Center,
            };
            nomGroup.SetBinding(Label.TextProperty, "TitleText");

BindingContext = this;

In my listview, I try to set this property with "set value" :

 //Design des cellules de groupe 
 var cellGroup = new DataTemplate(typeof(MyMenuHeader));
 cellGroup.CreateContent();
 cellGroup.SetValue(MyMenuHeader.TitleTextproperty, _dataMenu._nomMenu);
 HeaderTemplate = cellGroup;

but my property is set but never displayed in label.

Best regards,

EDIT: I had a new parameter to bindableproperty.create

 public static readonly BindableProperty TitleTextProperty =
 BindableProperty.Create("TitleText", typeof(String), typeof(MyRelaiTabCell), null, propertyChanged: OnTitleTextChanged);

        public String TitleText
        {
            get { return (String)GetValue(TitleTextProperty); }
            set { SetValue(TitleTextProperty, value); }
        }

this is this function which modifies the value of label when property changes:

static void OnTitleTextChanged(BindableObject bindable, object oldValue, object newValue)
{
    var menu = (bindable as MyRelaiTabCell);
    // Property changed implementation goes here
    menu._titleText.SetValue(Label.TextProperty, (newValue as String));
}

it's working, but only in one way. view-model --> viewcell. so when I set the value. When I try to get value when changing I didn't have the information.

0

There are 0 answers