title: WPF Set the Corner Radius of a Border through a Converter
body: <p>I would like to set the bottom Corner Radius of a ListView Item for just the "last" item in the list. I've attempted to do so with a Converter (which in fact finds the last row), but to no avail.</p>
  
  <p>The desirable effect is when the Converter returns true after finding the last item in the ListView, the border CornerRadius on the last ListViewItem is set to CornerRadius="0,0,10,10". For all other items in the ListView, CornerRadius="0,0,0,0"</p>
  
  <p>What I've done so far.</p>
  
  <p>The Converter...</p>
  
  <pre><code>public class IsLastItemConverter : IValueConverter
     {
         #region IValueConverter Members
         public object TrueValue { get; set; }
         public object FalseValue { get; set; }
  
         public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
         {
          ListViewItem item = value as ListViewItem;
          ListView listView = ItemsControl.ItemsControlFromItemContainer(item) as ListView;
          if (listView != null)
          {
  
              int index = listView.ItemContainerGenerator.IndexFromContainer(item);
              if (index == listView.Items.Count - 1)
              {
                  TrueValue = true;
                  return (bool)TrueValue;
              }
              else
              {
                  FalseValue = false;
                  return (bool)FalseValue;
              }
  
          }
              FalseValue = false;
              return (bool)FalseValue;
         }
  
      public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
         {
          // Just Convert Back
          return true;
         }
         #endregion
     }
  </code></pre>
  
  <p>The XAML...</p>
  
  <pre><code>&lt;local:IsLastItemConverter x:Key="lastItemConverter" 
                                     TrueValue="0,0,10,10" FalseValue="0,0,0,0"/&gt;
  
  
  &lt;DataTemplate x:Key="CellContentTemplate"&gt;
                          &lt;Border 
                              x:Name="CellContentBorder"
                              Background="{StaticResource GrayCharcoal}"                          
                              BorderThickness="4,4,4,4"                           
                              BorderBrush="{StaticResource Gray}"
                              CornerRadius="{Binding Converter={StaticResource lastItemConverter}, 
                              RelativeSource={RelativeSource AncestorType={x:Type ListViewItem}}}"
                              HorizontalAlignment="Left" 
                              Width="210" 
                              Height="50"                         
                              ContextMenu="{StaticResource MarginalUnitsContextMenu}" 
                              ScrollViewer.VerticalScrollBarVisibility="Hidden"&gt;...
  </code></pre>
  
  <p>Thoughts and ideas much appreciated - Glenn</p>