Good afternoon to all!
I have the next trouble in my WPF app.
I have a TabControl and with a Converter, I achieve to resize the width of the Tabitems . This Is working fine.
Now, in my app, I want have a Button to remove some of these TabItems and at the same time resize the rest of the TabItems. Whenever I remove one of the included TabItems, an error is taking place in my converter (Tabcontrol on the code below is null). What am I doing wrong?
My converter is like this:
public class TabSizeConverterVertical : IMultiValueConverter
{
public object Convert(object[] values, Type targetType, object parameter,
System.Globalization.CultureInfo culture)
{
TabControl tabControl = values[0] as TabControl;
double height = tabControl.ActualHeight / tabControl.Items.Count;
return (height <= 1) ? 0 : (height);
}
public object[] ConvertBack(object value, Type[] targetTypes, object parameter,
System.Globalization.CultureInfo culture)
{
throw new NotSupportedException();
}
}
and I use this converter in a style defined for TabItem (below)
<Setter Property="Height">
<Setter.Value>
<MultiBinding Converter="{StaticResource tabSizeVertical}">
<Binding RelativeSource="{RelativeSource Mode=FindAncestor,
AncestorType={x:Type TabControl}}" />
<Binding RelativeSource="{RelativeSource Mode=FindAncestor,
AncestorType={x:Type TabControl}}" Path="ActualHeight" />
</MultiBinding>
</Setter.Value>
</Setter>
Thanks for all.