سؤال

XAML:

<toolkit:ListPicker x:Name="profession" SelectionChanged="ListPicker_SelectionChanged">
    <toolkit:ListPickerItem Content="Value1" />
</toolkit:ListPicker>

How can I add a key to the ListPickerItem to be used in the C# code?

What I want is similar to HTML's value attribute for the option control.

Example of what I want: (C# code, OFC not working..)

int a = profession.SelectedItem.Key;
هل كانت مفيدة؟

المحلول

You can use the Tag property.

<toolkit:ListPickerItem Content="Value1" Tag="1"/>
var a = ((ListPickerItem)profession.SelectedItem).Tag;

نصائح أخرى

If you are trying to do this when your app first loads, then in your MainPage.xaml.cs file, include this in your constructor:

public MainPage(){
     InitializeComponent();

     profession.Items.Add("Value2"); // Add this line here
}

Otherwise, put this line wherever you need it.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top