我是Windows手机开发的新手。在我的应用程序中,我有一个包含
listpicker字段的表单,我想把这个字段作为必填字段。有什么方法可以做到吗?
提前致谢!
答案 0 :(得分:0)
嗨,请试试这个
<强> XAML 强>
<Grid x:Name="LayoutRoot">
<toolkit:ListPicker x:Name="Listpickername"
Margin="37,42,149,430"
Foreground="Black"
ExpansionMode="ExpansionAllowed"
Background="#FFF7EBEB" SelectionChanged="Listpickername_SelectionChanged">
</toolkit:ListPicker>
<Button Content="Check" Click="checklistitem" HorizontalAlignment="Left" Margin="143,344,0,0" VerticalAlignment="Top" Width="236"/>
</Grid>
C#:
string param =&#34;&#34;;
public PanoramaPage1()
{
InitializeComponent();
Listpickername.Items.Add("Item1");
Listpickername.Items.Add("Item2");
}
private void Listpickername_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (Listpickername.SelectedItem!=null)
{
param = Listpickername.SelectedItem.ToString();
}
}
private void checklistitem(object sender, RoutedEventArgs e)
{
if(param==string.Empty)
{
MessageBox.Show("Please select item");
}
else
{
MessageBox.Show("selected item is " + param);
}
}