我想要做的是只有当TabItem IsSelected和Expander IsExpanded
时才能看到tabitem内容我现在面临的问题是:
- 如果Expander IsHitTestVisible =" False" TabItem IsSelected但扩展器不扩展(/ Collapse)
- 如果Expander IsHitTestVisible =" True"然后TabItem不是
已选择,但扩展器确实展开(/折叠)
我需要IsHitTestVisible =" False"和IsHitTestVisible =" True"。我怎样才能实现这种行为?
我知道扩展器中没有真正的内容 我只想在转换器中使用IsExpanded的值(并且箭头可以上下移动)
我想要的是扩展器将点击传递给TabItem
<TabItem x:Name="tabitem3">
<TabItem.Header>
<Expander Header="Three" x:Name="tabexp3"/>
</TabItem.Header>
<TextBlock Text="Content Three TabItem" Background="Honeydew" >
<TextBlock.Visibility>
<MultiBinding Converter="{StaticResource bvc2}" Mode="OneWay">
<Binding ElementName="tabexp3" Path="IsExpanded"/>
<Binding ElementName="tabitem3" Path="IsSelected" />
</MultiBinding>
</TextBlock.Visibility>
</TextBlock>
</TabItem
public class VisabilityConverterTwoBool : IMultiValueConverter
{
public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
//if (values == null) return Visibility.Visible;
//if (values.Length != 2) return Visibility.Visible;
if (values.Length != 2) return Visibility.Collapsed;
if (values[0] as bool? == null || values[1] as bool? == null)
{
Debug.WriteLine(values[0].ToString());
Debug.WriteLine(values[1].ToString());
return Visibility.Collapsed;
}
//if (values.Length != 2 && values[0] as bool? == null || values[1] as bool? == null) return Visibility.Visible;
try
{
Debug.WriteLine(((bool)values[0]).ToString() + " " + ((bool)values[1]).ToString());
if ((bool)values[0] && (bool)values[1]) return Visibility.Visible;
else return Visibility.Collapsed;
}
catch (Exception ex)
{
Debug.WriteLine(ex.Message, "VisabilityConverterTwoBool");
Debug.WriteLine(values[0].ToString());
Debug.WriteLine(values[1].ToString());
}
return Visibility.Visible;
}
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)
{
return null;
}
}
答案 0 :(得分:0)
请尝试以下代码。
<TabControl>
<TabItem Header="First">
</TabItem>
<TabItem x:Name="tabitem3">
<TabItem.Header>
<Expander Header="Three" x:Name="tabexp3" IsExpanded="{Binding Path=IsSelected, ElementName=tabitem3,Mode=TwoWay}"/>
</TabItem.Header>
<TextBlock Text="Content Three TabItem" Background="Honeydew" >
<TextBlock.Visibility>
<MultiBinding Converter="{StaticResource bvc2}" Mode="OneWay">
<Binding ElementName="tabexp3" Path="IsExpanded"/>
<Binding ElementName="tabitem3" Path="IsSelected" />
</MultiBinding>
</TextBlock.Visibility>
</TextBlock>
</TabItem>
</TabControl>
答案 1 :(得分:0)
我在expandar上展开和折叠事件
private void expcolp(object sender, RoutedEventArgs e)
{
if (manualCollapse) return;
if (!(sender is Expander)) return;
Expander exp = (Expander)sender;
var d = sender as DependencyObject;
DependencyObject parent = VisualTreeHelper.GetParent(d);
while (parent != null)
{
if (parent is TabItem)
{
TabItem tabitem = (TabItem)parent;
if (!tabitem.IsSelected)
{
tabitem.IsSelected = true;
if (!exp.IsExpanded) exp.IsExpanded = true;
}
break;
}
d = parent as DependencyObject;
parent = VisualTreeHelper.GetParent(d);
}
}