2015-01-20 4 views
0

longlistselector ...를 클릭하면 longlistselector에서 통화 중 표시기를 표시하는 방법 아래 코드를 게시했습니다.선택한 항목이 변경되면 longlistselector에서 통화 중 표시기를 표시하는 방법은 무엇입니까?

항상 첫 번째 항목을 표시하고 있지만 어떤 항목을 클릭하는지 보여주고 싶습니다.

<StackPanel x:Name="top" Height="54" Orientation="Horizontal" Margin="-13,0,0,0" VerticalAlignment="Top" Background="#FF0FA3C0"> 
        <TextBlock TextWrapping="Wrap" Text="{Binding InspectionNumber}" Foreground="#FFF4F4FA" VerticalAlignment="Top" FontSize="26.667" Margin="10,0" Width="200"/> 
        <StackPanel Orientation="Horizontal"> 
         <TextBlock TextWrapping="Wrap" Text="{Binding Status}" FontSize="21.333" FontWeight="Bold" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="0,0,15,0" Width="150" FlowDirection="RightToLeft" Foreground="#FFF4F4FA"/> 
         <Border BorderBrush="#CC9D9D9F" BorderThickness="0,0,1,0" HorizontalAlignment="Left" VerticalAlignment="Center" Width="1" Height="30" Margin="0,0,10,0"/> 
         <Grid HorizontalAlignment="Right" Width="40" Height="40" VerticalAlignment="Center"> 
          <Image x:Name="sncIcon" HorizontalAlignment="Left" Height="40" VerticalAlignment="Top" Width="40" Source="{Binding CloudIcon, Mode=TwoWay,UpdateSourceTrigger=Default}" Tap="CloudIcon_Tap"/> 
          <telerikPrimitives:RadBusyIndicator x:Name="radbusyofflinedownload" HorizontalAlignment="Center" VerticalAlignment="Center" Visibility="Collapsed" Margin="-20,0,0,0" IsRunning="True" AnimationStyle="AnimationStyle8" Foreground="Black" FontSize="24"/> 
         </Grid> 
        </StackPanel> 
       </StackPanel> 

private DependencyObject FindChildControl<T>(DependencyObject control, string ctrlName) 
    { 
     int childNumber = VisualTreeHelper.GetChildrenCount(control); 
     for (int i = 0; i < childNumber; i++) 
     { 
      DependencyObject child = VisualTreeHelper.GetChild(control, i); 
      FrameworkElement fe = child as FrameworkElement; 
      // Not a framework element or is null 
      if (fe == null) return null; 

      if (child is T && fe.Name == ctrlName) 
      { 
       // Found the control so return 
       return child; 
      } 
      else 
      { 
       // Not found it - search children 
       DependencyObject nextLevel = FindChildControl<T>(child, ctrlName); 
       if (nextLevel != null) 
        return nextLevel; 
      } 
     } 
     return null; 
    } 



private async void InformationListSelector_SelectionChanged(object sender, SelectionChangedEventArgs e) 
    { 
     RadBusyIndicator radBusyIndicator = FindChildControl<RadBusyIndicator>(this, "radbusyofflinedownload") as RadBusyIndicator; 
     radBusyIndicator.Visibility = Visibility.Visible; 
    } 

도와주세요.

답변

0

첫째, 클래스

private bool _busyIndicatorIsVisible; 

    public bool BusyIndicatorIsVisible 
    { 
     get 
     { 
      return _busyIndicatorIsVisible; 
     } 
     set 
     { 
      if (_busyIndicatorIsVisible != value) 
      { 
       _busyIndicatorIsVisible = value; 
       this.OnPropertyChanged("BusyIndicatorIsVisible"); 
      } 
     } 
    } 

의 속성을 만들이 클래스에서 INotifyPropertyChanged 인터페이스를 구현합니다.

다음으로, 컨버터 가시성에 바인딩을 사용 :

<telerikPrimitives:RadBusyIndicator x:Name="radbusyofflinedownload" Visibility="{Binding BusyIndicatorIsVisible, Converter={StaticResource BoolVisibilityConverter}}" /> 

컨버터 :

public class BoolVisibilityConverter : IValueConverter 
{ 
    public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) 
    { 
     return (bool)value ? Visibility.Visible : Visibility.Collapsed; 
    } 

    public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) 
    { 
     throw new NotImplementedException(); 
    } 
} 

가 DataContext를 설정하는 것을 잊지 마세요.

마지막 InformationListSelector_SelectionChanged에

private async void InformationListSelector_SelectionChanged(object sender, SelectionChangedEventArgs e) 
{ 
    this.BusyIndicatorIsVisible = true; 
} 

[편집] RadBusyIndicator가 DataTemplate이있는 경우 :

<telerikPrimitives:RadBusyIndicator x:Name="radbusyofflinedownload" Visibility="{Binding ElementName=NAMELONGLISTSELECTOR,Path=DataContext.BusyIndicatorIsVisible,Converter={StaticResource BoolVisibilityConverter}}" /> 
관련 문제