WP 7.1 Listpicker:选择值显示对象名称而不是属性

时间:2013-01-21 07:46:58

标签: binding windows-phone-7.1 listpicker

我的WPP的ListPicker出了问题,我选择的值没有显示绑定,而是显示我作为ItemSource的模型的对象名称。但是,当我去FullModeItemTemplate时,我的绑定工作正常。我检查了我的输出,没有任何绑定错误..

这是我的代码。

public class TurnoverModel
{
    public string TurnoverId { get; set; }
    public string TurnoverDesc { get; set; }
}

我的模型iam作为集合传递给ItemSource

         <toolkit:ListPicker ItemsSource="{Binding TurnoverList}" Width="350" HorizontalAlignment="Left" Name="turnOverListPicker" SelectionMode="Multiple"}" Header="Turnover" SelectionChanged="OnTurnoverChanged">
            <toolkit:ListPicker.ItemTemplate>
                <DataTemplate>
                    <StackPanel Orientation="Horizontal">
                        <TextBlock Text="{Binding TurnoverDesc}"/>
                    </StackPanel>
                </DataTemplate>
            </toolkit:ListPicker.ItemTemplate>
            <toolkit:ListPicker.FullModeItemTemplate>
                <DataTemplate>
                    <StackPanel Orientation="Horizontal">
                        <TextBlock Text="{Binding TurnoverDesc}" Width="150"/>
                    </StackPanel>
                </DataTemplate>
            </toolkit:ListPicker.FullModeItemTemplate>
        </toolkit:ListPicker>

如果有人有任何想法,为什么我的绑定不起作用,我会感谢所有的回答, THX

1 个答案:

答案 0 :(得分:0)

 <toolkit:ListPicker ItemsSource="{Binding TurnoverList}" Width="350" HorizontalAlignment="Left" Name="turnOverListPicker" SelectionMode="Multiple"}" Header="Turnover" SelectionChanged="OnTurnoverChanged"> 
<toolkit:ListPicker.FullModeItemTemplate>
 <DataTemplate> 
<StackPanel Orientation="Horizontal"> 
<TextBlock Text="{Binding TurnoverDesc}" Width="150"/>
 </StackPanel>
 </DataTemplate>
 </toolkit:ListPicker.FullModeItemTemplate>
 </toolkit:ListPicker> 
关于selectionchanged事件的

写:

 private void OnTurnoverChanged(object sender, SelectionChangedEventArgs e)
    {
     TurnoverModel selecteditem = e.AddedItems[0] as TurnoverModel;
     String turnoverId =selecteditem.TurnoverId;
     String turnoverDesc =selecteditem.TurnoverDesc; 
    }
========================================================================