title: How to hightlight an item in one listbox based on selection on the other listbox using wpf
body: <p>I am doing my first project by using wpf/mvvm and get stuck here. I really need your help and suggestion. Thanks in advance.</p>
  
  <p>I am doing a report filter building screen, which allow the user to create and maintain a list of filters. the ReportFilter object has four properties: status, party, absencecode &amp; fitlername, getting from database. Whenever a user select a filter by clicking filtername in a listbox, the associated status(a group of radio buttons), party(a group of radio buttons) &amp; absencecode(a listbox containing a list of absence code) will be checked/highlighted. I can make radio buttons checked based on selection. But can't highlight the item in listbox for absencecode. When debugging, I can get selectedFilter.AbsenceCode for listbox of absencecode in Convert(). But I don't know how to compare the value from the list and highlight it. Like what param to pass to ConverterParameter for comparing? </p>
  
  <p>Following is some of my code:</p>
  
  <pre><code>public class ReportFilter : ModelBase
  {
      String _Status;
      String _Party;
      String _AbsenseCode;
      String _FilterName;
  
      public String AbsenseCode
      {
          get { return _AbsenseCode; }
          set
          {
              if (_AbsenseCode == value)
                  return;
              _AbsenseCode = value;
              OnPropertyChanged("AbsenseCode");
          }
      }
      ....
   }
  
  
  public class ReportsViewModel : ModelBase
  {
      private ReportFilter _selectedFilter;
      public ReportFilter selectedFilter
      {
          get
          {
              return _selectedFilter;
          }
          set
          {
              _selectedFilter = value;
              OnPropertyChanged("selectedFilter");
          }
      }
   ......
  </code></pre>
  
  <p>Following is xaml code:</p>
  
  <pre><code>    &lt;!-- absence code list --&gt;
      &lt;ListBox Name="Absence
  Code" ItemsSource="{Binding absenseCodeItems}" SelectedItem="{Binding seletedFilter.AbsenseCode,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" Grid.Row="1" Grid.Column="1" Grid.RowSpan="5" Margin="20,0,20,5" &gt;
         &lt;ListBox.ItemContainerStyle&gt;
            &lt;Style TargetType="ListBoxItem"&gt;
               &lt;Setter Property="IsSelected"  Value="{Binding Path=DataContext.selectedFilter.AbsenseCode, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type GroupBox}},  Converter={StaticResource IsItemSelected}, ConverterParameter=}"/&gt;
             &lt;/Style&gt;
         &lt;/ListBox.ItemContainerStyle&gt;
      &lt;/ListBox&gt;
  
      &lt;!-- filter list --&gt;
      &lt;ListBox Name="FilterListbox" ItemsSource="{Binding Path=filterItems}" Grid.Row="1" Grid.RowSpan="4" Grid.Column="2" Margin="20,0,20,5"  SelectedItem="{Binding selectedFilter, Mode=OneWayToSource, UpdateSourceTrigger=PropertyChanged}"&gt;
      &lt;/ListBox&gt;
  </code></pre>
  
  <p>A group of radio buttons for status:</p>
  
  <pre><code>&lt;RadioButton GroupName="Group1" Name="Current"  Grid.Column="0" Foreground="White" Content="Current" Margin="10,0,0,0" IsChecked="{Binding Path=selectedFilter.Status, Converter={StaticResource BooleanToStringValueConverter}, ConverterParameter=C}"/&gt;
  
  &lt;RadioButton GroupName="Group2" Name="Historical" Grid.Column="1" Foreground="White" Content="All Historical" IsChecked="{Binding Path=selectedFilter.Status, Converter={StaticResource BooleanToStringValueConverter}, ConverterParameter=A}"/&gt;
  </code></pre>
  
  <p>......</p>
  
  <p>Convertor in view model:</p>
  
  <pre><code>.....
      public class IsItemSelected : IValueConverter
      {
          public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
          {
              if (System.Convert.ToString(value).Equals(System.Convert.ToString(parameter)))
              {
                  return true;
              }
              return false;
          }
  .....
  </code></pre>