我正在开发对话框工具包fork的自定义控件部分,但是我在这里遇到了一些麻烦。
我已经包含了item source作为构造函数的一个属性,但我的问题是如何将选择器控件的值传递回构造函数。
public PickerView(string title, string message, IEnumerable ItemSource, string text = null, Keyboard keyboard = null)
{
InitializeComponent();
txtInput.Text = text;
BindTexts(title, message);
txtInput.Keyboard = keyboard;
pickItems.ItemsSource = ItemSource.Cast<object>().ToList();
pickItems.SelectedIndexChanged += PickItems_SelectedIndexChanged;
}
控件的实例化方式是通过
Task<T> GetPickerChoice<T>(string title, string message, IEnumerable ItemSource, string currentText = null,
Keyboard keyboard = null);
我希望能够获得用户从xamrian选择器控件中选择的结果,该控件在此事件中设置
private void PickItems_SelectedIndexChanged(object sender, EventArgs e)
{
throw new NotImplementedException();
}
我需要一些方法来将结果传递回它初始化的方式,我在下面的列表中传递。
List<PickerModel> _testList = new List<PickerModel>();
PickerModel model = new PickerModel();
model.Value = 1008;
model.Description = "FW";
_testList.Add(model);
var returnValueFromPicker= await Plugin.DialogKit.CrossDiaglogKit.Current.GetPickerChoice<PickerModel>("Fuel", $"This item is in one or more bins please select a bin location", _testList, null, Keyboard.Numeric);
我希望选取器的值为returnValueFromPicker的值。
发布于 2019-10-11 21:54:28
我最终要做的是添加一个事件处理程序
public event EventHandler<string> Picked;
当用户单击弹出菜单的ok按钮时,我基本上调用了它,并返回控件的选定项,以防其他人发现这个有用的东西。
private void Confirm_Clicked(object sender, EventArgs e)
{
Picked?.Invoke(this, pickItems.SelectedItem.ToString());
}
发布于 2019-10-12 10:49:13
您还可以在PickerView中添加一个可绑定的命令。使用这种方法,您可以将ViewModel的命令绑定到它(如果您使用MVVM模式)。
为此,您可能需要添加
public static BindableProperty ConfirmedCommandProperty = BindableProperty.Create(
propertyName: nameof(ConfirmedCommand),
returnType: typeof(ICommand),
declaringType: typeof(YourPickerClass),
defaultValue: null);
public ICommand ConfirmedCommand
{
get { return (ICommand)GetValue(ConfirmedCommandProperty); }
set { SetValue(ConfirmedCommandProperty, value); }
}
给你的采摘者。然后你可以绑定到一个视图层上。
https://stackoverflow.com/questions/58348534
复制相似问题