This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class DemoModel : UIPickerViewModel | |
{ | |
public Dictionary<string, string[]> options = new Dictionary<string, string[]>() | |
{ | |
{ "America", new string[] { "Mexico", "USA" } }, | |
{ "Europe", new string[] { "Germany", "France", "Italy"} }, | |
{ "Asia", new string[] { "Korea", "Japan"} }, | |
}; | |
public override nint GetComponentCount(UIPickerView pickerView) => 2; // This determines how many columns are rendered | |
public override nfloat GetComponentWidth(UIPickerView picker, nint component) => component == 0 ? 120f : 160f; | |
public override nfloat GetRowHeight(UIPickerView picker, nint component) => 40f; | |
/// <summary> | |
/// Determines the number of rows to render in a component | |
/// </summary> | |
public override nint GetRowsInComponent(UIPickerView pickerView, nint component) | |
{ | |
if (component == 0) | |
return options.Keys.Count; | |
else | |
{ | |
var driver = pickerView.SelectedRowInComponent(0); | |
return options.Values.ElementAt((int)driver).Length; | |
} | |
} | |
/// <summary> | |
/// Gets the display value for a row in a component | |
/// </summary> | |
public override string GetTitle(UIPickerView pickerView, nint row, nint component) | |
{ | |
if (component == 0) | |
return options.Keys.ElementAt((int)row); | |
else | |
{ | |
var driver = pickerView.SelectedRowInComponent(0); | |
return options.Values.ElementAt((int)driver).ElementAt((int)row); | |
} | |
} | |
[Export("pickerView:didSelectRow:inComponent:")] | |
public override void Selected(UIPickerView pickerView, nint row, nint component) | |
{ | |
// Update the display for column 2 if the value of column 1 has changed | |
if (component == 0) | |
{ | |
pickerView.ReloadComponent(1); | |
pickerView.Select(0, 1, false); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment