c# - 将 Stepper 值绑定到相应的列表视图项的参数 - Xamarin.forms
问题描述
我将步进器放在 listview 上,因此每条记录都有一个步进器。我想将 stepper onchanged 值绑定到相应的对象参数值之一。因此,每个列出的记录的参数都可以通过相应的步进器进行更改。有可能这样做吗?这是列表视图:
<ListView x:Name="TempMenuListView" HasUnevenRows="true" Grid.Row="2" SeparatorColor="Black" >
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<Grid Padding="10">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Label Text="{Binding PiattoTipo}" Grid.Row="0" Grid.Column="0" TextColor="Black" />
<Label Text="{Binding Piatto}" Grid.Row="0" Grid.Column="1" TextColor="Black" />
<Label x:Name="numeroPiattiLabel" Text="{Binding NumeroPiatti}" Grid.Row="0" Grid.Column="2" TextColor="Black" />
<Stepper x:Name="stepper" Maximum="20" ValueChanged="OnStepperValueChanged"/>
</Grid>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
这是 ListView 数据的类:
[Table("TempMenu")]
public class TempMenu
{
[PrimaryKey, AutoIncrement]
public int Id { get; set; }
public DateTime Date { get; set; }
public int TavoloNo { get; set; }
public string PiattoTipo { get; set; }
public string Piatto { get; set; }
public int NumeroPiatti { get; set; }
}
一个空的 OnStepperValueChanged 方法:
private void OnStepperValueChanged(object sender, ValueChangedEventArgs e)
{
}
我需要步进器来改变可观的NumeroPiatti
价值。
解决方案
首先,我建议您将实体(表类)和模型分开,您将使用这些模型在页面中显示一些内容。它会导致编写更多代码,但维护起来更干净、更好,特别是如果你想INotifyPropertyChanged
在这个模型中实现。
如果您想遵循 MVVM,请确保您的模型实现了INotifyPropertyChanged
您还可以制作一些基本模型或用于Fody
删除一些样板代码。
其余部分与您在上一条评论中提到的相同,您可以通过Stepper
这种方式使用控制:
//... rest of your code XAML
<Stepper x:Name="stepper" Maximum="20" Value={Binding SomePropertyInModel} />
//... rest of your code XAML
祝你编码好运!
推荐阅读
- html - 如何将图片并排放置,每个图片下方都有文字?
- tmux - 没有数字编号窗口的 TMUX 会话
- javascript - 为什么在 MERN 堆栈中找不到我的 POST 路由?
- python - sklean 使用文本和分类值机器学习预测二进制值
- html - 如何删除图标和周围div之间的空间
- python - 如何将差异最大的数字分成不同的组
- mongodb - MongoDb Primary Oplog one hour behing realtime
- javascript - 当第一个系列超过第二个时,echarts如何更改背景颜色
- excel - Excel 公式在尝试计算加班时间或更短时间时不起作用
- cypress - cy.fixture 不在循环内执行