listpicker fullmode不更新选择

时间:2014-10-16 20:09:39

标签: c# windows-phone-8 listpicker

我已经从我正在处理的应用中创建了一个测试应用。我有一个带有一组颜色的listpicker,出于某种原因,当它进入fullmode时,选择没有被更新。

我已经下载了2个这样的例子,我看不出我错过了什么。感谢

 <phone:PhoneApplicationPage.Resources>
    <DataTemplate x:Name="lstColorsItemTemplate">
        <StackPanel Orientation="Horizontal">
            <Rectangle Fill="{Binding pickedColorBlock}" Height="30" Width="30"/>
            <TextBlock Text="{Binding pickedColor}" Foreground="{StaticResource PhoneAccentBrush}" Margin="10,0,0,0" />
        </StackPanel>
    </DataTemplate>
    <DataTemplate x:Name="fulllstColorsItemTemplate" >
        <StackPanel Orientation="Horizontal" >
            <Rectangle Fill="{Binding pickedColorBlock}" Height="30" Width="30" Margin="0,0,10,10"  />
            <TextBlock Text="{Binding pickedColor}" Foreground="{StaticResource PhoneAccentBrush}" Margin="10,0,0,0" FontSize="20" />
        </StackPanel>
    </DataTemplate>
</phone:PhoneApplicationPage.Resources>


    <StackPanel Orientation="Horizontal" Margin="13,113,143,0">
        <toolkit:ListPicker x:Name="lstColors"  Width="225"                             
                            ItemTemplate="{StaticResource lstColorsItemTemplate}" 
                            FullModeItemTemplate="{StaticResource fulllstColorsItemTemplate}"
                            Header="Font Color"
                            BorderBrush="{StaticResource PhoneAccentBrush}"
                            Background="#FFF4F4F5"
                            CacheMode="BitmapCache"/>
    </StackPanel>

背后的代码

 protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e) //without ToDoTableEntries  not set as observablcollection throws null error (never counts up)
    {

        List<colorChoices> source = new List<colorChoices>();
        source.Add(new colorChoices() { pickedColorBlock = Colors.Black.ToString(), pickedColor = "Black", pickedSolidColorBrush = new SolidColorBrush(Colors.Black) });
        source.Add(new colorChoices() { pickedColorBlock = Colors.White.ToString(), pickedColor = "White", pickedSolidColorBrush = new SolidColorBrush(Colors.White) });
        source.Add(new colorChoices() { pickedColorBlock = Colors.Red.ToString(), pickedColor = "Red", pickedSolidColorBrush = new SolidColorBrush(Colors.Red) });
        source.Add(new colorChoices() { pickedColorBlock = Colors.Brown.ToString(), pickedColor = "Brown", pickedSolidColorBrush = new SolidColorBrush(Colors.Brown) });
        source.Add(new colorChoices() { pickedColorBlock = Colors.Blue.ToString(), pickedColor = "Blue", pickedSolidColorBrush = new SolidColorBrush(Colors.Blue) });
        source.Add(new colorChoices() { pickedColorBlock = Colors.Gray.ToString(), pickedColor = "Gray", pickedSolidColorBrush = new SolidColorBrush(Colors.Gray) });

        lstColors.ItemsSource = source;

    }

    class colorChoices
    {

        public string pickedColorBlock { get; set; }
        public string pickedColor {get; set;}
        public SolidColorBrush pickedSolidColorBrush {get; set;}

    }

1 个答案:

答案 0 :(得分:1)

因为它在protected override void OnNavigatedTo

中重新加载了ItemSource

在构造函数中设置ItemSource,它将解决您的问题。


要明白我的意思,在lstColors.ItemsSource = source处设置一个断点,它会在第一次加载应用时中断,一旦从完整页面模式返回它就会中断,基本上会重置列表。