:: Home

  login:         
  passwords:  

WPF FAQs

WPF General Questions
Concepts Element Tree
Concepts Dependency Property
Concepts Attached Property
Concepts Routed Events
Concepts Resources.
Concepts Animation
Concepts Freezable Object
Concepts Input and Commands.
Concepts Layouts
XAML Inline Styles and Templates
XAML XML Namespaces
XAML Code Behind
XAML Custom Class
XAML Type Converters
Content Model ItemControl
Content Model HeaderedItemsControl
Content Model HeaderedContentControl
Content Model Content Control
Content Model Decorator Content Model
Content Model Panel Content Model
Documents Serialization and Storage
Documents Annotations
Documents Flow Content
Documents Printing
Graphics and Multimedia Rendering Graphics
Graphics and Multimedia Animation and Timing
Graphics and Multimedia 2D Graphics
Graphics and Multimedia 3D Graphics
Graphics and Multimedia Visual Layer
Control Customization Adorners
Control Customization Stylable controls
Control Customization ControlTemplates
Data Data Binding
Data DragandDrop
Data Serialization
Globalization and Localization Attributes
Globalization and Localization Comments
Globalization and Localization Globalization Struc
Application and Deployment ClickOnce
Application and Deployment Frame
Application and Deployment Page
Application and Deployment Navigation
Application and Deployment Setup
Application and Deployment Window
Interoperability Message Loops Between
Interoperability Win32 in WPF
Interoperability WPF in Win32
Interoperability Windows Forms and WPF
Security Trusted Security
Security Partial Trust Security
Tools Microsoft Expression Blend
Tools ZAM3D
Tools XAMLPAD
Controls ToolTip
Controls TextBlock
Controls TabControl
Controls ProgressBar
Controls PrintDialog
Controls Popup
Controls TextBox
Controls Canvas
Controls ComboBox
Controls ListBox
Controls StatusBar
Controls ToolBar
Controls Context Menu
Controls Expander
Controls DocumentViewer
Controls FlowDocumentReader
Controls GroupBox
Controls GridSplitter
Controls Image
Controls Menu
Controls ScrollBar
Controls Slider
Controls RichTextBox
Controls Border
Controls Buttons

SilverLight Interview Qs

SAP Interview Questions

Oracle Interview Questions

PHP Interview Questions

Ajax Interview Questions

IIS 7.0

OOP Interview Questions

Ruby Interview Questions

Sql Server Interview Questions

Winforms Interview Questions

SharePoint 2007 Questions

Microsoft Crm Questions

Concepts Element Tree Interview Questions & FAQs

Questions and answers for Concepts Element Tree

2. Concepts Element Tree

    2.1 How can I override the Logical Tree ?
    2.2 How can I enumerate all the descendants of a visual object ?

2.1 How can I override the Logical Tree ?

Although it is not necessary in most cases, advanced control authors have the option to override the logical tree. This example describes how to subclass 'StackPanel' to override the logical tree, in this case to enforce a behavior that the panel may only have and will only render a single child element.

Normal logical tree can be overridden as follows :

[C#]

public class SingletonPanel : StackPanel



private FrameworkElement _child;



public SingletonPanel() {



}



public FrameworkElement SingleChild

{



get { return _child;}

set

{

if (value==null) {

RemoveLogicalChild(_child);

} else {

if (_child==null) {

_child = value;

} else {


// raise an exception?

MessageBox.Show("Needs to be a single element");

}

}

}

}

public void SetSingleChild(object child)

{

this.AddLogicalChild(child);

}



public new void AddLogicalChild(object child)

{

_child = (FrameworkElement)child;

if (this.Children.Count == 1)

{

this.RemoveLogicalChild(this.Children[0]);

this.Children.Add((UIElement)child);

}

else

{

this.Children.Add((UIElement)child);

}

}



public new void RemoveLogicalChild(object child)



{

_child = null;

this.Children.Clear();

}

protected override IEnumerator LogicalChildren

{

get {

// cheat, make a list with one member and return the enumerator

ArrayList _list = new ArrayList();

_list.Add(_child);

return (IEnumerator) _list.GetEnumerator();}

}

}


2.2 How can I enumerate all the descendants of a visual object ?

If you want to serialize all the rendering information of a visual object hierarchy, you have to enumerate all the descendants of a visual object as follows :

[C#]



// Enumerate all the descendants of the visual object.

static public void EnumVisual(Visual myVisual)

{

for (int i = 0; i < VisualTreeHelper.GetChildrenCount(myVisual); i++)

{

// Retrieve child visual at specified index value.

Visual childVisual = (Visual)VisualTreeHelper.GetChild(myVisual, i);



// Do processing of the child visual object.



// Enumerate children of the child visual object.

EnumVisual(childVisual);

}

}

bottom user control
::  Home :: Services ::  Prices ::  Request Quote
Copyright 2007, Megasolutions Ltd