Как выбрать значения списка в Windows Phone 7? - PullRequest
0 голосов
/ 08 декабря 2010

Я делаю один пример приложения для календаря на день рождения. В этом я использую три списка управления, такие как дата, месяц и год. Используя 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 (б);

1 Ответ

2 голосов
/ 08 декабря 2010

Я действительно рекомендую использовать Silverlight Toolkit для Windows Phone . Имеет DatePicker элемент управления.

Если вы действительно хотите использовать свои собственные ComboBox элементы управления, я рекомендую вам по крайней мере использовать DateTime тип, доступный в C #, чтобы упростить задачу.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...