Click or drag to resize
AB4D logo

ReaderSvgGetElementsForLayerName Method

Returns a List of UIElements that are assigned to the layer with layerName (layers can be only defined in Microsoft Visio).

Namespace:  Ab2d
Assembly:  Ab2d.ReaderSvg (in Ab2d.ReaderSvg.dll) Version: 7.1.7295.1040
Syntax
C#
public List<UIElement> GetElementsForLayerName(
	string layerName
)

Parameters

layerName
Type: SystemString
name of the layer

Return Value

Type: ListUIElement
List of UIElements that are assigned to the layerName or null if layer does not exist.
Remarks

Ab2d.ReaderSvg has some methods that are specialized to read additional data from svg files that were created with Microsoft Visio.

It is possible to get the data about the layers and custom properties and data.

To get information about the layers use GetLayerNames or GetElementsForLayerName(String).

To get custom properties and associated data use:
GetCustomProperties(String)
GetCustomProperties(Object)
GetObjectsWithCustomProperties
GetCustomPropertiesDataTable

Examples

The following code is taken from OfficePlanSample and shows how to fill a LayersPanel with checkboxes - one for each layer defined in svg file. With checking or unchecking the checkboxes the elements associated to the layer are shown or hidden. The svg file is read with SvgViewbox that is defined in xaml.

C#
private void CollectLayers(Ab2d.ReaderSvg readerSvg)
{
    List<string> layers;

    // Get names of the layers defined in Visio
    // SvgOfficePlan is a SvgViewbox control defined in XAML
    layers = SvgOfficePlan.InnerReaderSvg.GetLayerNames();

    foreach (string oneLayerName in layers)
    {
        CheckBox newCheckBox;

        // Create a checkbox for each layer
        newCheckBox = new CheckBox();
        newCheckBox.Content = oneLayerName;
        newCheckBox.IsChecked = true;
        newCheckBox.Checked += new RoutedEventHandler(LayerRadioButton_Checked);
        newCheckBox.Unchecked += new RoutedEventHandler(LayerRadioButton_Checked);

        // Fill LayersPanel with checkboxes
        LayersPanel.Children.Add(newCheckBox);
    }
}

void LayerRadioButton_Checked(object sender, RoutedEventArgs e)
{
    string layerName;
    CheckBox changedCheckBox;

    changedCheckBox = (CheckBox)sender;

    layerName = (string)changedCheckBox.Content;

    // Show or hide all elements in the layer
    ShowHideLayerElements(layerName, changedCheckBox.IsChecked ?? false);
}

private void ShowHideLayerElements(string layerName, bool isVisible)
{
    List<UIElement> elementsForLayerName;

    // Get all UIElements that are connected to specified layer
    elementsForLayerName = SvgOfficePlan.InnerReaderSvg.GetElementsForLayerName(layerName);

    // TODO:
    // Because one object can be in multiple layers 
    // we should check that when showing an object 
    // all the layers for the objects should be visible

    foreach (UIElement oneElement in elementsForLayerName)
    {
        if (isVisible)
            oneElement.Visibility = Visibility.Visible;
        else
            oneElement.Visibility = Visibility.Collapsed;
    }
}        

public List<string> GetLayerNames()
{
    if (!Ab.Common.Licensing.ReaderSvg.CommonLicensing.IsCalledFromWellKnowApplication())
        CheckIfProVersion(true);

    if (_visioLayers == null)
        return null;
    else
        return _visioLayers.GetLayerNames();
}
XAML
<svg:SvgViewbox Name="SvgOfficePlan" Source="Resources/Office plan.svg"/>
See Also