2012-02-22 2 views
0

Microsoft 예제를 사용하고 있지만 몇 가지 사항을 변경하고 있습니다. 선택 목록에서 데이터를 채울 수 있지만 항목을 선택한 후에는 선택한 항목으로 다시 가져 오지 않습니다. 나는 틀린 것이 확실하지 않다. sys : string 데이터를 쿼리로 대체하려고합니다. 내가 도대체 ​​뭘 잘못하고있는 겁니까? 여기 wp7 ListPicker 채우기

<phone:PhoneApplicationPage 
x:Class="WO_App.Page1" 
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone" 
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone" 
xmlns:sys="clr-namespace:System;assembly=mscorlib"  
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit" 


FontFamily="{StaticResource PhoneFontFamilyNormal}" 
FontSize="{StaticResource PhoneFontSizeNormal}" 
Foreground="{StaticResource PhoneForegroundBrush}" 
SupportedOrientations="Portrait" Orientation="Portrait" 
mc:Ignorable="d" d:DesignHeight="768" d:DesignWidth="480" 
shell:SystemTray.IsVisible="True"> 

<Grid x:Name="LayoutRoot" Background="Transparent"> 

    <Grid.RowDefinitions> 
     <RowDefinition Height="Auto"/> 
     <RowDefinition Height="*"/> 
    </Grid.RowDefinitions> 

    <StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28"> 
     <TextBlock x:Name="ApplicationTitle" Text="MY APPLICATION" Style="{StaticResource PhoneTextNormalStyle}"/> 
     <TextBlock x:Name="PageTitle" Text="ListPicker" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/> 
    </StackPanel> 

    <!--ContentPanel - place additional content here--> 
    <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0"> 
     <toolkit:ListPicker x:Name="TestList" Header="Select a part" ExpansionMode="FullscreenOnly"> 

      <!--This is the data I am trying to replace with binding 
      <sys:String>1</sys:String> 
      <sys:String>2</sys:String> 
      <sys:String>3</sys:String> 
      <sys:String>4</sys:String> 
      <sys:String>5</sys:String> 
      <sys:String>6</sys:String> 
      <sys:String>7</sys:String> 
      <sys:String>8</sys:String> 
      <sys:String>9</sys:String> 
      <sys:String>10</sys:String> 
      <sys:String>11</sys:String> 
      <sys:String>12</sys:String> 
      <sys:String>13</sys:String>--> 

      <toolkit:ListPicker.FullModeItemTemplate> 
       <DataTemplate> 
        <StackPanel Orientation="Horizontal" Margin="16 21 0 20"> 
         <TextBlock Text="{Binding Num}" 
            Margin="0 0 0 0" 
            FontSize="43" 
            FontFamily="{StaticResource PhoneFontFamilyLight}"/> 
        </StackPanel> 
       </DataTemplate> 
      </toolkit:ListPicker.FullModeItemTemplate> 
     </toolkit:ListPicker> 
     <Button Content="Chosen" Height="72" HorizontalAlignment="Left" Margin="284,179,0,0" Name="Button1" VerticalAlignment="Top" Width="160" /> 
    </Grid> 

</Grid>    

는 VB 코드이다.

Partial Public Class Page1 
Inherits PhoneApplicationPage 

Public Sub New() 
    InitializeComponent() 
End Sub 

Private Sub PhoneApplicationPage_Loaded(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles MyBase.Loaded 

    Dim source As New List(Of Numbers) 

    For x = 1 To 15 
     source.Add(New Numbers(x)) 
    Next x 

    Me.TestList.ItemsSource = source 

End Sub 

Private Sub Button1_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles Button1.Click 

    Dim selectedItem As String = Me.TestList.SelectedItem.ToString 
    Dim selectedIndex As String = Me.TestList.SelectedIndex 

    MessageBox.Show("you chose " & selectedItem & vbCrLf & selectedIndex) 
End Sub 

Public Class Numbers 
    Public Property Num() As Integer 
     Get 
      Return m_Num 
     End Get 
     Set(value As Integer) 
      m_Num = value 
     End Set 
    End Property 
    Private m_Num As Integer 

    Public Sub New(myNum As Integer) 
     Me.Num = myNum 
    End Sub 

End Class 


End Class 
+0

에 오신 것을 환영합니다! 귀하의 솔루션을 질문에 편집하는 대신 대답으로 게시하십시오. 그러면 질문과 대답이 무엇인지 명확하게 알 수 있습니다. 감사! –

답변

0

나는 u는 또한 항목 템플릿을 사용할 필요가 있다고 생각 : 스택 오버플로

<toolkit:ListPicker.ItemTemplate> 
      <DataTemplate> 
       <StackPanel> 
        <TextBlock Text="{Binding Num}"         
           FontSize="28" 
           FontFamily="{StaticResource PhoneFontFamilyLight}"/> 
       </StackPanel> 
      </DataTemplate> 
     </toolkit:ListPicker.temTemplate> 
+0

그게 내가 끝내 준거야. – sonicbabbler