0
當應用程序打開時,ListPicker的selectedItem,即「BackgroundColor」必須來自變量。如何實現這一目標?selecteditem或selectedindex作爲列表選取器
XAML:
<phone:PhoneApplicationPage.Resources>
<DataTemplate x:Name="PickerItemTemplate">
<TextBlock Text="{Binding BackGroundColorString}" />
</DataTemplate>
<DataTemplate x:Name="PickerFullModeItemTemplate" >
<Grid x:Name="rootGrid" Margin="0">
<StackPanel Orientation="Horizontal" Margin="0 14 0 0" HorizontalAlignment="Center">
<TextBlock Name="BackgroundColor"
Text="{Binding BackGroundColorString}"
FontSize="35"
Margin="10,10"
TextAlignment="Center"
FontFamily="/Assets/Fonts/AGENCYR.TTF#Agency FB"
/>
</StackPanel>
</Grid>
</DataTemplate>
</phone:PhoneApplicationPage.Resources>
<toolkit:ListPicker x:Name="BackgroundColor" FullModeHeader="Select Background Color:"
Header="Background Color:" BorderThickness="0"
FullModeItemTemplate="{StaticResource PickerFullModeItemTemplate}"
ItemTemplate="{StaticResource PickerItemTemplate}" Background="#FF09043C"
SelectionChanged="BackgroundColor_SelectionChanged" >
</toolkit:ListPicker>
C#:
public class BackGroundlistPickerClass
{
public string BackGroundColorString
{
get;
set;
}
}
List<BackGroundlistPickerClass> BackGroundColorList = new List<BackGroundlistPickerClass>();
public void ImplementListPickeritems() //Listpickers
{
BackGroundColorList.Add(new BackGroundlistPickerClass() { BackGroundColorString = "White (Default)" });
BackGroundColorList.Add(new BackGroundlistPickerClass() { BackGroundColorString = "Black" });
BackGroundColorList.Add(new BackGroundlistPickerClass() { BackGroundColorString = "Light Grey" });
}
string PreSelectedColor="Black";
private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
{
BackgroundColor.SelectedItem=PreSelectedColor; // ERROR COMES ON THIS LINE
}
BackgroundColor.SelectedItem
不工作,因爲在BackgroundColor
項目從類別/列表是acutaly。現在如何在頁面打開時將BackgroundColor listpicker設置爲Black(PreSelectedColor)?