0
votes

What I want to do is have the tabitem content only visible when the TabItem IsSelected and Expander IsExpanded

The problem I have right now is:
- if the Expander IsHitTestVisible="False" then the TabItem IsSelected but the Expander does not Expand (/Collapse)
- if the Expander IsHitTestVisible="True" then the TabItem Is NOT Selected but the Expander does Expand (/Collapse)

What I need the the behavior of both IsHitTestVisible="False" and IsHitTestVisible="True". How can I achieve that behavior?

I know there is not real content in the Expander
I just want the value of IsExpanded to use in the Converter (and for the arrow to go up and down)

What I want is for the Expander to pass the click on to the 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;
    }
}
2
Can you post the converterAyyappan Subramanian
@Ganesh Converter returns visible if both are true and otherwise collpsedpaparazzo

2 Answers

0
votes

Try the below code.

<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>
0
votes

I did it with expand and collapse event on the 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);
    }
}