【发布时间】:2021-03-03 11:14:49
【问题描述】:
你好,我想通过 xaml 中的按钮传递标签 它是一个列表视图,每一行都有她自己的标签,我想通过标签更新每一行
<Label Grid.Column="2"
Grid.Row="1"
Text="{Binding Label}"
FontSize="20"
TextColor="Black"
Margin="0,10,0,0"
FontFamily="{StaticResource font}"
HorizontalOptions="Start"
VerticalOptions="Center"/>
<ImageButton Grid.Column="2"
Grid.Row="0"
HorizontalOptions="End"
VerticalOptions="End"
Source="plus.png"
Margin="9"
clicked ="update"
BackgroundColor="Transparent"/>
以及类中的函数
public void update (object sender, EventArgs e) { 按标签更新 }
我知道有一些命令,但我是初学者,我不知道如何使用它我试过这个但我没有工作。
Command="{Binding Path=BindingContext.UpdateCommand, Source={x:Reference Name=listViewEvent}}"
CommandParameter="{Binding Label}"
功能是这样的
UpdateCommand = new Command<string>(async (args) => {
String Label = args as string;
DisplayAlert("update", "update", "OK");
_ = Navigation.PushAsync(new AddReminder(Label));
});
并且警报没有显示 请问我需要帮助
【问题讨论】:
-
点击按钮时是否要更新标签文本的值?
-
不,我想通过标签更新sqlite中的对象
-
我们可以为模型添加一些属性并将它们绑定到标签上。通过这种方式,我们可以获取 ViewModel 中的属性。在 MVVM 中传递元素并不是一个好的设计。
标签: xamarin xamarin.forms xamarin.android xamarin.ios