如果我先选择1,然后选择用户更改项目,为什么不更改相应的选择器?

时间:2019-04-09 02:44:19

标签: c# xml xaml picker

如果用户首先选择2个,则可以将选择的项目更改为1,但是如果选择了1个,则不会将相应的选择器数量更改为显示2个选择器,为什么不更改呢?

 void ItemSelected(object sender, System.EventArgs e)
 {
    //to get value user selected
    //var drainx = drain.Items[drain.SelectedIndex];
    //DisplayAlert(drainx, "selected Value", "OK");

    string drainxy = drain.Items[drain.SelectedIndex]; 


    switch (drainxy)
    {
    case "1":
    DisplayAlert(drainxy, "selected Value", "OK");
    drainPicker1();
    drain2Picker.IsVisible = false;
    drain3Picker.IsVisible = false;
    drain4Picker.IsVisible = false;
    break;
    case "2":
    DisplayAlert(drainxy, "selected Value", "OK");
    drainPicker1();
    drainPicker2();
    drain3Picker.IsVisible = false;
    drain4Picker.IsVisible = false;
    break;
    }
 }

“关于排水和捡水器”

<Picker x:Name="drain" Title="Drain #" 
Margin="190,-30,50,0" TextColor="{StaticResource pinkColor}"
SelectedIndexChanged="ItemSelected"/>  

<Picker x:Name="drain1Picker" Title="Drain 1 Location" />
<Picker x:Name="drain2Picker" Title="Drain 2 Location" />
<Picker x:Name="drain3Picker" Title="Drain 3 Location" />
<Picker x:Name="drain4Picker" Title="Drain 4 Location" />

1 个答案:

答案 0 :(得分:0)

switch (drainxy)
    {
    case "1":
    DisplayAlert(drainxy, "selected Value", "OK");
    drainPicker1();
    drain2Picker.IsVisible = false;
    drain3Picker.IsVisible = false;
    drain4Picker.IsVisible = false;
    break;
    case "2":
    DisplayAlert(drainxy, "selected Value", "OK");
    drainPicker1.IsVisible = true;
    drainPicker2.IsVisible = true;
    drain3Picker.IsVisible = false;
    drain4Picker.IsVisible = false;
    break;
    }
 }