I created a custom view and want to bind a property which is list or observationCollection.
when I add items to the list in viewModel the list in custom view will be changed to .
how to do it?
It seems that it can not use bindableProperty
I created a custom view and want to bind a property which is list or observationCollection.
when I add items to the list in viewModel the list in custom view will be changed to .
how to do it?
It seems that it can not use bindableProperty
Hello,
Welcome to Microsoft Q&A!
Firstly take a look at Bindable Layouts in Xamarin.Forms .
Bindable layouts enable any layout class that derives from the Layout<T> class to generate its content by binding to a collection of items .
BindableLayout
exposes the attached properties (including ItemsSource ,ItemTemplate) .
The usage is pretty simple
<StackLayout BindableLayout.ItemsSource="{Binding User.TopFollowers}"
Orientation="Horizontal"
...>
<BindableLayout.ItemTemplate>
<DataTemplate>
<controls:CircleImage Source="{Binding}"
Aspect="AspectFill"
WidthRequest="44"
HeightRequest="44"
... />
</DataTemplate>
</BindableLayout.ItemTemplate>
</StackLayout>
Note : While it's technically possible to attach a bindable layout to any layout class that derives from the Layout<T> class, it's not always practical to do so, particularly for the AbsoluteLayout
, Grid
, and RelativeLayout
classes.
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
Is that I am saying wrong?
I created a custom view with a List or ObservationCollection Property.
public static readonly BindableProperty ValuesProperty= BindableProperty.Create(nameof(ElectricityValues),
typeof(List<Models.Equipments.TimeAndCurrent>),
typeof(PoChart),
new List<Models.Equipments.TimeAndCurrent>(),
BindingMode.OneWay,
propertyChanged: OnPropertyChanged);
but when binding to it in xaml . when I add or remove items from the Items which is binded to the Values
it is not changed.
Try to change the type from List<Models.Equipments.TimeAndCurrent>
to ObservableCollection<Models.Equipments.TimeAndCurrent>
.
7 people are following this question.