The end goal to be able to set a specific ItemContainerStyle
on the first and last element in my list box;
The converters thus far are:
public class IsFirstItemConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
bool result = false;
result = ((IList<object>)parameter).First() == value;
return result;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}
public class IsLastItemConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
bool result = false;
result = ((IList<object>)parameter).Last() == value;
return result;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}
And implementation:
<DataTrigger Value="True" Binding="{Binding Converter={StaticResource IsFirstItemConverter},ConverterParameter=Items, ElementName=SubItems}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ListBoxItem}">
<StackPanel Orientation="Horizontal">
<TextBlock Text="First"/>
<ContentPresenter/>
</StackPanel>
</ControlTemplate>
</Setter.Value>
</Setter>
</DataTrigger>
And the error is:
InvalidCastException: Unable to cast object of type 'System.String' to type 'System.Collections.Generic.IList`1[System.Object]'.
Im sure I screwed up in multiple spots, just not experienced enough with XAML and bindings to narrow down where.