删除TabItem时调整TabControl的大小 [英] Resize TabControl when delete a TabItem
问题描述
大家下午好!
我的WPF应用程序遇到了下一个麻烦。
我有一个TabControl和一个转换器,我实现调整Tabitems的宽度。这工作正常。
现在,在我的应用程序中,我想要一个Button来删除其中一些TabItems,同时调整其余TabItems的大小。每当我删除其中一个包含的TabItems时,我的转换器中发生错误(以下代码上的Tabcontrol为null)。我做错了什么?
我的转换器是这样的:
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;
//Subtract 1, otherwise we could overflow to two rows.
return (height <= 1) ? 0 : (height);
}
public object[] ConvertBack(object value, Type[] targetTypes, object parameter,
System.Globalization.CultureInfo culture)
{
throw new NotSupportedException();
}
}
我在为TabItem定义的样式中使用此转换器(下图)
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.
推荐答案
首先你做的干净的解决方案
然后运行项目它会成功
享受
first you do "clean solution"
then run the project it will successful
enjoy
这篇关于删除TabItem时调整TabControl的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!