作者:七彩咩_131 | 来源:互联网 | 2023-01-27 19:08
更新: 提醒一下,如果有人可以告诉我如何在不使用手势的情况下实现此功能,那么就有500点奖金>
我正在使用ViewCell和手势识别器打开一个带有以下代码的选择器.ViewCell左侧有一个标签,右侧有一个标签区域,最初在应用程序启动时填充,稍后在单击ViewCell时使用选择器填充.
XAML
C#这适用于使用CommandParameter的不同选择器(ati,bti,pti等)
public SettingsPage()
{
InitializeComponent();
BindingCOntext= new CommandViewModel();
}
void atiPickerSelectedIndexChanged(object sender, EventArgs e)
{
var picker = (Picker)sender;
int selectedIndex = picker.SelectedIndex;
if (selectedIndex != -1)
{
App.DB.UpdateIntSetting(Settings.Ati, selectedIndex);
atiLabel.Text = AS.ati.Text();
}
}
void ptiPickerSelectedIndexChanged(object sender, EventArgs e)
{
var picker = (Picker)sender;
int selectedIndex = picker.SelectedIndex;
if (selectedIndex != -1)
{
App.DB.UpdateIntSetting(Settings.Pti, selectedIndex);
ptiLabel.Text = AS.pti.Text();
}
}
public class CommandViewModel: ObservableProperty
{
public ICommand openPickerCommand;
public CommandViewModel()
{
openPickerCommand = new Command(PickerFocus);
//openPickerCommand = new Command(tapped);
}
public ICommand OpenPickerCommand
{
get { return openPickerCommand; }
}
void PickerFocus(Picker param)
{
param.Focus();
}
}
我想删除TapGestureRecognizers的使用,但我仍然希望保留功能和布局.
有人向我建议,如果我像这样使用ViewCell的Tapped事件会更好:
Tapped="OnTapped"
有人可以详细解释我如何用C#连接它.我是否最好在CommandViewModel以及C#支持代码中编写代码.视图模型还有一个方法可以使用参数,因此它可以用来打开不同的选择器吗?
我非常感谢我如何做到这一点的一个例子.请注意,如果有一种方法可以通过.cs支持代码进行编码,我并不特别需要使用CommandViewModel.