Intersoft ClientUI Documentation
AncestorLevel Property



Gets or sets the level of ancestor to look for, in FindAncestor mode. Use 1 to indicate the one nearest to the binding target element.
Syntax
Public Property AncestorLevel As Integer
Dim instance As BindingDescriptor
Dim value As Integer
 
instance.AncestorLevel = value
 
value = instance.AncestorLevel
public int AncestorLevel {get; set;}
public:
property int AncestorLevel {
   int get();
   void set (    int value);
}
Remarks

FindAncestor is used to bind the target with a specific ancestor element type defined in specific ancestor level range. This mode is commonly used when you know that a specific ancestor element type existed on certain level.

In this mode, you specify the AncestorType to determine the type of the target that will be bound and the AncestorLevel to determine how far it will look up for the ancestor with types specifed in AncestorType.

The default value of AncestorLevel is 1, so it will look at up one time and check whether the current ancestor match the type specified in AncestorType. If it matches, it will continue with the binding process.

The following example shows how to use FindAncestor mode to bind the elements inside ItemTemplate of a UXListBox to UXListBoxItem as their ancestor.

XAML
Copy Code
<Intersoft:UXListBox ItemsSource="{Binding Collection}" ImageMemberPath="Image" ItemContentType="ContentAndImage" 
                        ItemImageHeight="32" ItemImageWidth="32" HorizontalScrollBarVisibility="Disabled">
    <Intersoft:UXListBox.ItemTemplate>
        <DataTemplate>
            <StackPanel>
                <TextBlock Text="{Binding Name}"/>
                <StackPanel Orientation="Horizontal">
                    <Intersoft:BindingFramework.Binding>
                        <Intersoft:BindingDescriptor TargetProperty="Visibility" SourceProperty="IsSelected"
                                                                    Mode="FindAncestor" AncestorType="UXListBoxItem"
                                                                    Converter="{StaticResource VisibilityConverter}"/>
                    </Intersoft:BindingFramework.Binding>
                    <Intersoft:UXHyperlinkButton Content="Details" IsToggleButton="False" Foreground="Navy"/>
                    <Intersoft:UXHyperlinkButton Content="Order" IsToggleButton="False" Foreground="Navy" Margin="8,0,0,0"/>
                </StackPanel>
            </StackPanel>
        </DataTemplate>
    </Intersoft:UXListBox.ItemTemplate>
</Intersoft:UXListBox>
C#
Copy Code
public class VisibilityConverter : IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        if (value is bool && targetType == typeof(Visibility))
        {
            if ((bool)value)
                return Visibility.Visible;
            else
                return Visibility.Collapsed;
        }

        return value;
    }

    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    {
        if (value is Visibility && targetType == typeof(bool))
        {
            if (((Visibility)value) == Visibility.Visible)
                return true;
            else
                return false;
        }

        return value;
    }
}

This sample bind the Visibility property of StackPanel to the IsSelected property of UXListBoxItem using FindAncestor. Notice that the BindingDescriptor also supports IValueConverter.

Requirements

Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also

Reference

BindingDescriptor Class
BindingDescriptor Members

Concepts

Data Binding Overview

Send Feedback