0

Listpicker를 사용하여 사용자가 색상을 선택할 수 있도록합니다. 그래서 목록 상자를 표시하는 Textbox를 포함하는 DataTemplate과 함께 Toolkit Listpicker를 사용했습니다. 내가 원하는 것은 페이지가로드 될 때 이전에 선택한 색상 (항목)이 자동으로 선택되는 것입니다. 그러나 그것은 항목이 단순히 추가되지 않기 때문에 명백한 'System.InvalidOperationException'예외를 제공하지만 datatemplate 텍스트 상자를 통해 예외입니다. 제발 도와주세요 :DataTemplate이있는 ListPicker의 SelectedIndex 또는 SelectedItem


<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> 

      <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"> 
       <TextBlock Name="BackgroundColor" 
        Text="{Binding BackGroundColorString}" 
          /> 
      </StackPanel> 
     </Grid> 
    </DataTemplate> 
        </phone:PhoneApplicationPage.Resources> 

if (SunderGutkaSettings.Contains(SG_KEY_BACKGROUNDCOLOR)) //check if key is not present, read value 
     { 
      if (BackGroundColorList.Count != 0)//test if list if not empty 
      { 

       var ListPickerBackGroundColorRead = BackGroundColorList[singletonInstance.SelectedFontColorIndex] as BackGroundlistPickerClass; //pull whole class 

       string ListPickerBackGroundColorReadString = ListPickerBackGroundColorRead.BackGroundColorString; 

       int ListPickerBackGroundColorReadStringToIndex = BackGroundColorList.FindIndex(x => x.BackGroundColorString.StartsWith(ListPickerBackGroundColorReadString)); 

       BackgroundColor.SelectedIndex = ListPickerBackGroundColorReadStringToIndex; //DISABLE FOR testing      


      } 

을 사실, 내 코드 simplyfing에 : BackgroundColor.SelectedIndex = 0; 작업하지 않음 도 아니요 BackgroundColor.SelectedItem = "Red";

도움말 나

+0

질문이 명확하지 않습니다! 너 뭐하려고? – Sajeetharan

+0

DataTemplate이있는 ListPicker의 SelectedItem을 설정하는 방법은 무엇입니까? –

+0

그리고 ItemsSource가 무엇입니까? –

답변

0

항목을 설정하려면

This.BackgroundColor.SelectedItem = YourObject; 

이 당신은 아마 당신이 목록 피커

private void BackgroundColor_SelectionChanged(object sender, SelectionChangedEventArgs e) 
    { 
     var item = (sender as ListPicker).SelectedItem; 
    } 
바인딩 객체로 캐스팅 할 필요가 ListPicker의 selectedItem가 얻을하는 방법입니다