후 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
나의 발견은 선택된 인덱스 방법 내 부착 된 프로젝트입니다. 나는 왜 이런 식으로 행동하는지 알지 못한다 ..
, 당신은 무엇을 얻고있다? 국가 이름 또는 국가 목록? – nkchandra
나는 국가 이름을 얻고 그 이름으로 국가의 색인을 찾고 선택된 색인 –
로 설정하여 해당 국가의 색인을 찾습니다. 따라서 선택한 국가가 변경되어 selectedIndex가 변경되지 않아 UI가 변경되지 않았습니까? 새롭게 설정된 SelectedIndex가 SelectedIndex와 동일하면 SelectionChanged 이벤트가 발생하지 않습니다. – nkchandra