Reputation: 237
i want to increment or decrement value of label based on stepper value change, but stuck here. Here is my code
<ListView x:Name="mylistview"
>
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<StackLayout HorizontalOptions="StartAndExpand">
<Label HorizontalOptions="Center" Text="{Binding Qty, StringFormat='Qty. {0:N}'}" FontSize="11"
TextColor="Black" />
<Stepper ValueChanged="stepper_ValueChanged" Minimum="0" Maximum="10" x:Name="stepper" Value="{Binding Qty}" Increment="0.1" HorizontalOptions="LayoutOptions.Center" VerticalOptions="LayoutOptions.CenterAndExpand" />
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
Upvotes: 0
Views: 633
Reputation: 12723
1.In the code,if you just want bind label text to stepper you can do this.
<ListView x:Name="mylistview">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<StackLayout HorizontalOptions="StartAndExpand">
<Label HorizontalOptions="Center" BindingContext="{x:Refrence Name=stepper}" Text="{Binding Path=Value, StringFormat='Qty. {0:N}'}" FontSize="11"
TextColor="Black" />
<Stepper ValueChanged="stepper_ValueChanged" Minimum="0" Maximum="10" x:Name="stepper" Increment="0.1" HorizontalOptions="LayoutOptions.Center" VerticalOptions="LayoutOptions.CenterAndExpand" />
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
just add bindcontext to label,then bind stepper's value,this labe text can be changed by stepper.if have a problem,you can refer to hereofficial document
2,When you use modle bingding data,you should use INotifyPropertyChanged to your modle,if this do not have ,the value can not be changed.
3,when you use modle,according to your code the Qty should be contained to listview's itemsource,not contained just in BindContext,so the Qty can be useful.
Upvotes: 1
Reputation: 1225
How you can achieve is through below steps, if you are using MVVM
Upvotes: 0