Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
.NET Framework 3.5
Visual Class
Visual Methods
 RemoveVisualChild Method
Collapse All/Expand All Collapse All
This page is specific to
Microsoft Visual Studio 2008/.NET Framework 3.5

Other versions are also available for the following:
.NET Framework Class Library
Visual..::.RemoveVisualChild Method

Removes the parent-child relationship between two visuals.

Namespace:  System.Windows.Media
Assembly:  PresentationCore (in PresentationCore.dll)
Visual Basic (Declaration)
Protected Sub RemoveVisualChild ( _
    child As Visual _
)
Visual Basic (Usage)
Dim child As Visual

Me.RemoveVisualChild(child)
C#
protected void RemoveVisualChild(
    Visual child
)
Visual C++
protected:
void RemoveVisualChild(
    Visual^ child
)
JScript
protected function RemoveVisualChild(
    child : Visual
)
XAML
You cannot use methods in XAML.

Parameters

child
Type: System.Windows.Media..::.Visual
The child visual object to remove from the parent visual.

The RemoveVisualChild method removes the parent-child relationship between two visuals. This method, along with the AddVisualChild method, must be used when you need greater low-level control over the underlying storage implementation of visual child objects. VisualCollection can be used as a default implementation for storing child objects.

The following example shows how to define custom storage requirements for a visual child. The example uses the AddVisualChild and RemoveVisualChild methods to sets up the parent-child relationship between the parent visual and child. In order for the visual tree to be enumerated correctly, the example provides overridden implementations of the GetVisualChild method and VisualChildrenCount property.

NoteNote:

Although it is possible to use VisualCollection to create parent-child relationships between visual objects, it is more efficient to provide your own custom storage implementation when only one child is linked to a parent.

C#
// Create a host visual derived from the FrameworkElement class.
// This class provides layout, event handling, and container support for
// the child visual object.
public class MyVisualHost : FrameworkElement
{
    private DrawingVisual _child;

    public MyVisualHost(DrawingVisual drawingVisual)
    {
        _child = drawingVisual;
        this.AddVisualChild(_child);
    }

    public DrawingVisual Child
    {
        get
        {
            return _child;
        }

        set
        {
            if (_child != value)
            {
                this.RemoveVisualChild(_child);
                _child = value;
                this.AddVisualChild(_child);
            }
        }
    }

    // Provide a required override for the VisualChildrenCount property.
    protected override int VisualChildrenCount
    {
        get { return _child == null ? 0 : 1; }
    }

    // Provide a required override for the GetVisualChild method.
    protected override Visual GetVisualChild(int index)
    {
        if (_child == null)
        {
            throw new ArgumentOutOfRangeException();
        }

        return _child;
    }

Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks | Privacy Statement
Page view tracker