2014-10-16 76 views
1

我從我正在開發的應用程序創建了一個測試應用程序。我有一個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;} 

    } 
+0

你是什麼意思,它沒有得到更新?你的意思是你不知道FullScreenMode中的哪個項目是SelectedItem? – 2014-10-17 00:19:40

+0

對不起,當我點擊我的列表時,它將帶我到全模式屏幕我選擇我的新顏色,它將我返回到我的原始頁面,但SelectedItem不會更改它保持第一個選項。 – branedge 2014-10-17 01:58:41

回答

1

它,因爲它重新加載的ItemSource在protected override void OnNavigatedTo

設置的ItemSource在構造函數,它會解決你的問題。


要明白我的意思把一個破發點,在lstColors.ItemsSource = source這將打破第一次應用程序被加載,它會破壞一旦它從全頁模式回來,基本上重置列表。

+0

謝謝。那在我的測試應用程序(我發佈的那個)上工作的奇怪的事情是它不會在我的「真實」的應用程序工作。我從我的測試應用程序複製了代碼,並粘貼到我的真實應用程序,它不會工作。我卸載並重新安裝了Windows Phone工具包,並注意到一旦我選擇了顏色後,它會跳轉到全屏頁面,我選擇顏色它會返回到頁面,但選擇不會更改,但如果再次單擊顏色在它進入全屏之前,它會將顏色選擇更改爲我之前選擇的顏色。 – branedge 2014-10-17 15:26:13

+0

現在試圖複製和粘貼真實應用程序中的代碼來測試應用程序,並查看它是什麼打破它。但注意到測試應用程序是Windows Phone的Silverlight 8.1和真正的應用程序是Windows Phone 8.可以這樣做嗎?我沒有升級我的真實應用程序到8.1,但沒有解決它... – branedge 2014-10-17 17:21:11

+0

@ user2712080我在WP8.0 SL上測試它,它適用於我。在我看來,您的「真實」應用程序與您的「測試」應用程序(其工作原理)不同。我的猜測是你的「真實」應用與ListPicker混淆。 – 2014-10-18 00:05:02