2012-06-15 3 views
1

후 WP7의 UI를 갱신하지 내 윈도우 폰 7ListPicker의 설정을 선택한 지수는 비동기 호출

에 두 개의 실버 listpicker 컨트롤이 것은 여기에 대한 내 XAML입니다. 사용자가 자동으로 반대뿐만 아니라 그 나라의 국가 코드를 설정합니다 다음 국가 이름을 선택하면 국가 이름

<toolkit:ListPicker x:Name="listPickerCountryLogin" SelectionChanged="listPickerCountryLogin_SelectionChanged" Height="72" HorizontalAlignment="Left" Margin="14,43,0,0" VerticalAlignment="Top" Width="436" FullModeHeader="Select Country" Background="White" BorderBrush="White" Foreground="{StaticResource listPickerBrush}"> 
          <toolkit:ListPicker.ItemTemplate> 
           <DataTemplate> 
            <StackPanel Orientation="Horizontal"> 
             <TextBlock Text="{Binding Country}" Width="250" /> 
            </StackPanel> 
           </DataTemplate> 
          </toolkit:ListPicker.ItemTemplate> 
          <toolkit:ListPicker.FullModeItemTemplate> 
           <DataTemplate> 
            <StackPanel Orientation="Horizontal"> 
             <TextBlock Text="{Binding Country}" Width="300" Margin="0,0,0,20" FontSize="24"/> 
            </StackPanel> 
           </DataTemplate> 
          </toolkit:ListPicker.FullModeItemTemplate> 
         </toolkit:ListPicker> 

// and here is my second listpciker for country codes 

        <toolkit:ListPicker x:Name="listPickerCCLogin" SelectionChanged="listPickerCCLogin_SelectionChanged" Height="56.3" Width="80" HorizontalAlignment="Left" Margin="14,100,0,0" VerticalAlignment="Top" FullModeHeader="Select Country" Background="White" BorderBrush="White" Foreground="{StaticResource listPickerBrush}"> 
         <toolkit:ListPicker.ItemTemplate> 
          <DataTemplate> 
           <StackPanel Orientation="Horizontal"> 
            <TextBlock Name="lblCC" Text="{Binding CC}" Width="235" /> 
           </StackPanel> 
          </DataTemplate> 
         </toolkit:ListPicker.ItemTemplate> 
         <toolkit:ListPicker.FullModeItemTemplate> 
          <DataTemplate> 
           <StackPanel Orientation="Horizontal"> 
            <TextBlock Text="{Binding Country}" Width="300" Margin="0,0,0,20" FontSize="24"/> 
           </StackPanel> 
          </DataTemplate> 
         </toolkit:ListPicker.FullModeItemTemplate> 
        </toolkit:ListPicker> 

에 대한

가 // 먼저 listpicker 지금 시나리오입니다.

나는이 목록에 대해 listpicker 선택 변경 이벤트를 사용하고 있습니다.

여기 내 C# 코드입니다.

먼저이 방법으로 국가 목록을 사용하여 내 listpickers를 바인딩합니다.

/// <summary> 
     /// Binding All Listpickers With Data 
     /// </summary> 
     protected void BindListPickers() 
     { 
      CountryListParser oCountryList = new CountryListParser(); 
      this.listPickerCountryLogin.ItemsSource = oCountryList.GetAllCountries(); 
      this.listPickerCCLogin.ItemsSource = oCountryList.GetAllCountries(); 
     } 

다음은 선택기 선택 변경 이벤트입니다.

/// <summary> 
     /// Country List Picker Of Login Selection Change Event 
     /// </summary> 
     /// <param name="sender"></param> 
     /// <param name="e"></param> 
     private void listPickerCountryLogin_SelectionChanged(object sender, SelectionChangedEventArgs e) 
     { 
      if (listPickerCountryLogin.SelectedIndex >= 0 && listPickerCountryLogin.SelectedIndex < listPickerCCLogin.Items.Count) 
       listPickerCCLogin.SelectedIndex = listPickerCountryLogin.SelectedIndex; 
     } 

/// <summary> 
/// Country Code List Picker Of Login Selection Change Event 
/// </summary> 
/// <param name="sender"></param> 
/// <param name="e"></param> 
private void listPickerCCLogin_SelectionChanged(object sender, SelectionChangedEventArgs e) 
{ 
    if (listPickerCCLogin.SelectedIndex >= 0 && listPickerCCLogin.SelectedIndex < listPickerCountryLogin.Items.Count) 
     listPickerCountryLogin.SelectedIndex = listPickerCCLogin.SelectedIndex; 
} 

여전히 내 코드는 오류없이 잘 작동합니다. 이제 내가 꼼짝 못하는 까다 롭고 어려운 부분을 찾아라. 하나의 Google 서비스를 호출하고 위도가 긴 사용자를 전달하면 사용자 국가가 반환되며 해당 국가를 내 목록 선택 도구로 설정하고 싶습니다. 여기

내 코드입니다

여전히 예외는 올 모든 것이 순조롭게 진행과 내 나라에 따라 내 listpicker 선택된 인덱스를 설정하지만, 당신에게 내 listpicker의 UI를 업데이트하지 그들을 빈 할 또는
protected void OnLocationServiceResponseRecieved(string response) 
     { 
      JObject o = JObject.Parse(response); 
      string Country = (string)o["countryname"]; 

      Dispatcher.BeginInvoke(new System.Action(delegate() 
      { 
       CountryListParser oCountryList = new CountryListParser(); 
       int countrytIndex = oCountryList.CountryIndexByName(Country); 
       this.listPickerCountryLogin.SelectedIndex = countrytIndex; 
       this.listPickerCCLogin.SelectedIndex = countrytIndex; 
      })); 
     } 

비어 있다고 말할 수 있습니다. 그러나 내가 원하는 백엔드에서 내 listpicker를 탭하면 원하는 국가가 이미 설정되어 있습니다. 하지만 업데이트되지 않았거나 UI 스레드에 집착하지 않았습니다. 지수는 그것은 의지가 비어가는 38 이상인 경우

So problem is UI is not updated properly 

=== 업데이트 ===

My Sample Code Where Issue Is Reproducing

나의 발견은 선택된 인덱스 방법 내 부착 된 프로젝트입니다. 나는 왜 이런 식으로 행동하는지 알지 못한다 ..

+0

, 당신은 무엇을 얻고있다? 국가 이름 또는 국가 목록? – nkchandra

+0

나는 국가 이름을 얻고 그 이름으로 국가의 색인을 찾고 선택된 색인 –

+0

로 설정하여 해당 국가의 색인을 찾습니다. 따라서 선택한 국가가 변경되어 selectedIndex가 변경되지 않아 UI가 변경되지 않았습니까? 새롭게 설정된 SelectedIndex가 SelectedIndex와 동일하면 SelectionChanged 이벤트가 발생하지 않습니다. – nkchandra

답변

0

3 일 동안 고생하고 나서이 문제를 해결했습니다. 이전에 나는 그것이 내 UI 스레드에서 문제라고 생각하고 있었고 상쾌하지 않았다. 그리고 그 부분에 초점을 맞 춥니 다. 그러나 3 일째에 나는 이것이리스트 피커 제어에서 잘못 될 수 있다는 것을 알아 차렸다. 그리고 나는 codeplex에 대해 공부했습니다. 어떤 사람들은 또한이 문제에 직면 해 있습니다. 그러나 내가 어떻게 수정했는지 말해 줄께. 나는 네 단계를 수행했다.

  1. 나는 내 프로젝트에서 모든 실버 라이트 툴킷 참조를 제거하고 해결책을 정리했다.

  2. 나는 PC에서 실버 라이트 툴킷을 설치하고 11 월 -2010 안정 버전을 설치하고 PC를 재시작하고 프로젝트에서이 새 설치에서 dll을 참조했습니다.

  3. 내 listpicker 컨트롤과 함께 선택한 색인도 바인딩했습니다. 당신의 비동기 결과에서

      <toolkit:ListPicker x:Name="listPickerCountryLogin" SelectionChanged="listPickerCountryLogin_SelectionChanged" Height="72" HorizontalAlignment="Left" Margin="14,43,0,0" VerticalAlignment="Top" Width="436" FullModeHeader="Select Country" Background="White" BorderBrush="White" Foreground="{StaticResource listPickerBrush}"> 
           <toolkit:ListPicker.Resources> 
            <Style TargetType="toolkit:ListPickerItem"> 
             <Setter Property="Padding" Value="8 6"/> 
            </Style> 
           </toolkit:ListPicker.Resources> 
           <toolkit:ListPicker.Style> 
            <StaticResource ResourceKey="ListPickerStyle"/> 
           </toolkit:ListPicker.Style> 
           <toolkit:ListPicker.ItemTemplate> 
            <DataTemplate> 
             <StackPanel Orientation="Horizontal"> 
              <TextBlock Text="{Binding Country}" Width="250" /> 
             </StackPanel> 
            </DataTemplate> 
           </toolkit:ListPicker.ItemTemplate> 
           <toolkit:ListPicker.FullModeItemTemplate> 
            <DataTemplate> 
             <StackPanel Orientation="Horizontal"> 
              <TextBlock Text="{Binding Country}" Width="300" Margin="0,0,0,20" FontSize="24"/> 
             </StackPanel> 
            </DataTemplate> 
           </toolkit:ListPicker.FullModeItemTemplate> 
          </toolkit:ListPicker> 
    
0

나는 (다른 서비스로 대체 한 Google 서비스를 제외하고) 전체 코드를 구현했으며, 완벽하게 작동하고 UI가 잘 업데이트된다. 코드에서 어떤 문제가 보이지 않습니다. 내 코드를 확인하십시오. HERE

So. 나는 당신이 'countryIndex'를 교차 점검 할 것을 제안합니다. 다른 일반 텍스트 블록을 만들고이 countryblock과 해당 값에이 countryIndex를 할당하십시오.

내 코드를 내 코드와 비교하여 단서를 얻을 수도 있습니다.

+0

제 질문에 대한 최신 업데이트를 참조하십시오. 샘플 프로젝트도 업로드했습니다. –

0

Panorama 응용 프로그램에서 ListPicker를 사용하는 동안 비슷한 문제가 발생했습니다.

나는 0에서 50까지의 항목 목록을 가지고 있습니다.

<toolkit:ListPicker x:Name="MyListPicker" ItemsSource="{Binding MyList}" Width="174" Margin="10, 10, 0, 0" ItemTemplate="{StaticResource MyTemplate}"> 
</toolkit:ListPicker> 

<DataTemplate x:Name="MyTemplate"> 
     <TextBlock Text="{Binding}" FontFamily="Calibri" FontSize="50" /> 
    </DataTemplate> 

그리고 제가 생각한 것처럼 38보다 큰 또는 40 (사용자처럼) UI가 목록 항목을 선택한 후에 업데이트되지 않았습니다. 그냥 빈 UI를 보여줍니다.

나는 또한 그들이 큰 목록에 대한 ListPicker를 사용하지 않는 것이 좋습니다 것을 알고,하지만 난 51 개 항목을 추측 확인 (또는하지 될 수있다?)

나는 따라서이 ListPicker 자체 내부의 문제가 될 수있다 생각합니다.