[英]How to select the listbox values in windows phone 7?
我正在為生日日歷做一個示例應用程序。 在那里我使用三個列表框控件,如日期,月份和年份。 使用listboxitem我在其中添加了數據。
<ListBox Height="56" HorizontalAlignment="Left" Margin="243,171,0,0" Name="listBox1" VerticalAlignment="Top" Width="207">
<ListBoxItem Content="01" HorizontalContentAlignment="Center" IsSelected="True" VerticalContentAlignment="Center" FontSize="32" FontWeight="Bold" FontFamily="Segoe WP Bold" BorderThickness="5" />
<ListBoxItem Content="02" HorizontalContentAlignment="Center" IsSelected="True" VerticalContentAlignment="Center" FontSize="32" FontWeight="Bold" FontFamily="Segoe WP Bold" BorderThickness="5"/>
<ListBoxItem Content="03" HorizontalContentAlignment="Center" IsSelected="True" VerticalContentAlignment="Center" FontSize="32" FontWeight="Bold" FontFamily="Segoe WP Bold" BorderThickness="5" />
<ListBoxItem Content="04" HorizontalContentAlignment="Center" IsSelected="True" VerticalContentAlignment="Center" FontSize="32" FontWeight="Bold" FontFamily="Segoe WP Bold" BorderThickness="5" />
<ListBoxItem Content="05" HorizontalContentAlignment="Center" IsSelected="True" VerticalContentAlignment="Center" FontSize="32" FontWeight="Bold" FontFamily="Segoe WP Bold" BorderThickness="5" />
<ListBoxItem Content="06" HorizontalContentAlignment="Center" IsSelected="True" VerticalContentAlignment="Center" FontSize="32" FontWeight="Bold" FontFamily="Segoe WP Bold" BorderThickness="5" />
<ListBoxItem Content="07" HorizontalContentAlignment="Center" IsSelected="True" VerticalContentAlignment="Center" FontSize="32" FontWeight="Bold" FontFamily="Segoe WP Bold" BorderThickness="5" />
<ListBoxItem Content="08" HorizontalContentAlignment="Center" IsSelected="True" VerticalContentAlignment="Center" FontSize="32" FontWeight="Bold" FontFamily="Segoe WP Bold" BorderThickness="5" />
<ListBoxItem Content="09" HorizontalContentAlignment="Center" IsSelected="True" VerticalContentAlignment="Center" FontSize="32" FontWeight="Bold" FontFamily="Segoe WP Bold" BorderThickness="5" />
<ListBoxItem Content="10" HorizontalContentAlignment="Center" IsSelected="True" VerticalContentAlignment="Center" FontSize="32" FontWeight="Bold" FontFamily="Segoe WP Bold" BorderThickness="5" />
<ListBoxItem Content="11" HorizontalContentAlignment="Center" IsSelected="True" VerticalContentAlignment="Center" FontSize="32" FontWeight="Bold" FontFamily="Segoe WP Bold" BorderThickness="5" />
<ListBoxItem Content="12" HorizontalContentAlignment="Center" IsSelected="True" VerticalContentAlignment="Center" FontSize="32" FontWeight="Bold" FontFamily="Segoe WP Bold" BorderThickness="5" />
<ListBoxItem Content="13" HorizontalContentAlignment="Center" IsSelected="True" VerticalContentAlignment="Center" FontSize="32" FontWeight="Bold" FontFamily="Segoe WP Bold" BorderThickness="5" />
<ListBoxItem Content="14" HorizontalContentAlignment="Center" IsSelected="True" VerticalContentAlignment="Center" FontSize="32" FontWeight="Bold" FontFamily="Segoe WP Bold" BorderThickness="5" />
<ListBoxItem Content="15" HorizontalContentAlignment="Center" IsSelected="True" VerticalContentAlignment="Center" FontSize="32" FontWeight="Bold" FontFamily="Segoe WP Bold" BorderThickness="5" />
<ListBoxItem Content="16" HorizontalContentAlignment="Center" IsSelected="True" VerticalContentAlignment="Center" FontSize="32" FontWeight="Bold" FontFamily="Segoe WP Bold" BorderThickness="5" />
<ListBoxItem Content="17" HorizontalContentAlignment="Center" IsSelected="True" VerticalContentAlignment="Center" FontSize="32" FontWeight="Bold" FontFamily="Segoe WP Bold" BorderThickness="5" />
<ListBoxItem Content="18" HorizontalContentAlignment="Center" IsSelected="True" VerticalContentAlignment="Center" FontSize="32" FontWeight="Bold" FontFamily="Segoe WP Bold" BorderThickness="5" />
<ListBoxItem Content="19" HorizontalContentAlignment="Center" IsSelected="True" VerticalContentAlignment="Center" FontSize="32" FontWeight="Bold" FontFamily="Segoe WP Bold" BorderThickness="5" />
<ListBoxItem Content="20" HorizontalContentAlignment="Center" IsSelected="True" VerticalContentAlignment="Center" FontSize="32" FontWeight="Bold" FontFamily="Segoe WP Bold" BorderThickness="5" />
<ListBoxItem Content="21" HorizontalContentAlignment="Center" IsSelected="True" VerticalContentAlignment="Center" FontSize="32" FontWeight="Bold" FontFamily="Segoe WP Bold" BorderThickness="5" />
<ListBoxItem Content="22" HorizontalContentAlignment="Center" IsSelected="True" VerticalContentAlignment="Center" FontSize="32" FontWeight="Bold" FontFamily="Segoe WP Bold" BorderThickness="5" />
<ListBoxItem Content="23" HorizontalContentAlignment="Center" IsSelected="True" VerticalContentAlignment="Center" FontSize="32" FontWeight="Bold" FontFamily="Segoe WP Bold" BorderThickness="5" />
<ListBoxItem Content="24" HorizontalContentAlignment="Center" IsSelected="True" VerticalContentAlignment="Center" FontSize="32" FontWeight="Bold" FontFamily="Segoe WP Bold" BorderThickness="5" />
<ListBoxItem Content="25" HorizontalContentAlignment="Center" IsSelected="True" VerticalContentAlignment="Center" FontSize="32" FontWeight="Bold" FontFamily="Segoe WP Bold" BorderThickness="5" />
<ListBoxItem Content="26" HorizontalContentAlignment="Center" IsSelected="True" VerticalContentAlignment="Center" FontSize="32" FontWeight="Bold" FontFamily="Segoe WP Bold" BorderThickness="5" />
<ListBoxItem Content="27" HorizontalContentAlignment="Center" IsSelected="True" VerticalContentAlignment="Center" FontSize="32" FontWeight="Bold" FontFamily="Segoe WP Bold" BorderThickness="5"/>
<ListBoxItem Content="28" HorizontalContentAlignment="Center" IsSelected="True" VerticalContentAlignment="Center" FontSize="32" FontWeight="Bold" FontFamily="Segoe WP Bold" BorderThickness="5" />
<ListBoxItem Content="29" HorizontalContentAlignment="Center" IsSelected="True" VerticalContentAlignment="Center" FontSize="32" FontWeight="Bold" FontFamily="Segoe WP Bold" BorderThickness="5" />
<ListBoxItem Content="30" HorizontalContentAlignment="Center" IsSelected="True" VerticalContentAlignment="Center" FontSize="32" FontWeight="Bold" FontFamily="Segoe WP Bold" BorderThickness="5" />
<ListBoxItem Content="31" HorizontalContentAlignment="Center" IsSelected="True" VerticalContentAlignment="Center" FontSize="32" FontWeight="Bold" FontFamily="Segoe WP Bold" BorderThickness="5" />
</ListBox>
所以,我想選擇那些列表框值,我必須添加(例如:24-MAR-1988表示= 24 + 03 + 88)。 我得到了指數值。
int a = int.Parse((listBox1.SelectedIndex + 1).ToString());
我無法獲得選定的值:
string b = listBox1.SelectedItem.ToString(); MessageBox.Show(b)中;
我真的建議您使用Windows Phone的Silverlight工具包 。 它有一個DatePicker
控件。
如果您確實要使用自己的ComboBox
控件,建議您至少使用C#中可用的DateTime
類型,以使事情變得更容易。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.