Windows Vista Forums
Vista Forums Home Join Vista Forums Donate Vista Tutorials Tags

Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Microsoft Technical Newsgroups > Avalon

Does FrameworkElement.RemoveLogicalChild(object child) work?

Closed Thread
 
Thread Tools Display Modes
Old 01-31-2006   #1 (permalink)
Jason Dolinger
Guest


 

Does FrameworkElement.RemoveLogicalChild(object child) work?

Last question for the day (today has been a doozy!):

Has anyone successfully used FrameworkElement.RemoveLogicalChild(object
child)? I'm attempting to insert a new object into the Logical Tree,
right in between the Window and the next level down (which is whatever
you've defined at the top level of your tree). The first step of this
process is removing that next level down element from the window's
logical tree, using the following approach (this code is in the
window.cs file):

// get the enumerator to the Window's logical children
IEnumerator children = this.LogicalChildren;

// move the first spot in the collection
children.MoveNext();

// Get the first element in the enumeration,
// this should be the first element below the window
FrameworkElement topLevelLogicalChild = (FrameworkElement)
children.Current;

// remove the child from the window's logical tree
this.RemoveLogicalChild(topLevelLogicalChild);



When I execute this code, the logical tree remains unchanged. While
debugging, I've also verified that what I get back from children.Current
is indeed the element that I want to remove. Most likely I'm doing
something wrong here, but perhaps there is a small bug this part of the
API? I wouldn't think that it'd be used all that much.

Thanks for any information on this,
Jason



Old 01-31-2006   #2 (permalink)
Michael Latta
Guest


 

Re: Does FrameworkElement.RemoveLogicalChild(object child) work?

The calls you are using are for managing the logical tree from within a
component. They exist mostly to notify some parts of the system that you
have already removed/added children to the tree. They do not perform the
add/remove. The management of children for the tree is the responsibility
of each element class, and in the WPF provided elements this is mostly at
the leaves not the common abstract classes. There is no single call to make
to add/remove from the tree. You need to test what kind of element it is
and use the proper child/children properties. For example a Panel has its
children in the Children property which you may use to add/remove children.
The Adorner classes use a single Child property. You need to look at what
Window exposes for managing the children in your case and code to that.
Also note that the collection under an enumeration may not be modified
during the enumeration, so even had it been possible to do what you had, it
would blow up when the enumeration attempted to access elements after the
remove operation. This sometimes means that you need to create a temporary
collection to hold elements that are to be removed/added while iterating
over the children of an element.

Michael
(C# / WPF MVP)


"Jason Dolinger" <jdolinger@lab49.com> wrote in message
news:%23dZkPkKGGHA.1388@TK2MSFTNGP11.phx.gbl...
> Last question for the day (today has been a doozy!):
>
> Has anyone successfully used FrameworkElement.RemoveLogicalChild(object
> child)? I'm attempting to insert a new object into the Logical Tree,
> right in between the Window and the next level down (which is whatever
> you've defined at the top level of your tree). The first step of this
> process is removing that next level down element from the window's logical
> tree, using the following approach (this code is in the window.cs file):
>
> // get the enumerator to the Window's logical children
> IEnumerator children = this.LogicalChildren;
>
> // move the first spot in the collection
> children.MoveNext();
>
> // Get the first element in the enumeration,
> // this should be the first element below the window
> FrameworkElement topLevelLogicalChild = (FrameworkElement)
> children.Current;
>
> // remove the child from the window's logical tree
> this.RemoveLogicalChild(topLevelLogicalChild);
>
>
>
> When I execute this code, the logical tree remains unchanged. While
> debugging, I've also verified that what I get back from children.Current
> is indeed the element that I want to remove. Most likely I'm doing
> something wrong here, but perhaps there is a small bug this part of the
> API? I wouldn't think that it'd be used all that much.
>
> Thanks for any information on this,
> Jason
>
>
>



Old 01-31-2006   #3 (permalink)
Jason Dolinger
Guest


 

Re: Does FrameworkElement.RemoveLogicalChild(object child) work?

Hmm... I think I understand what you are getting at, but the Windows
SDK doc clearly says for FrameworkElement.RemoveLogicalChild():

Removes the provided element from this element's logical tree.

I also just saw the ChangeLogicalParent() method. Am I to assume that
this also exhibits the behaviour that you describe?

If what you are saying is true, then what do I really need to do to
insert a new element right underneath the window in the logical tree?
The LogicalChildren property only has a get on it, and returns an
IEnumerator. That essentially means that there is no way to control the
logical children except through API methods provided which apparently
don't work. Is this something that I just shouldn't be doing and MS
doesn't want us to do?

To give you some context, I'm still trying to find a way to be able to
scale a borderless window up and down (This is one of 3 approaches that
I'm trying now, blocked on all 3!). I've found that if you used a
viewbox, the windows scales up and down nicely. However, I don't want
to use a viewbox all of the time, as I don't always want my content to
be scaled to the window size. So my idea was to programatically insert
a viewbox in the logical tree at the point that I want to zoom the
window down. Later when zooming it back up, I'd programatically remove
the ViewBox from the tree.

Does this sound crazy?

Thanks Michael!
Jason


Michael Latta wrote:
> The calls you are using are for managing the logical tree from within a
> component. They exist mostly to notify some parts of the system that you
> have already removed/added children to the tree. They do not perform the
> add/remove. The management of children for the tree is the responsibility
> of each element class, and in the WPF provided elements this is mostly at
> the leaves not the common abstract classes. There is no single call to make
> to add/remove from the tree. You need to test what kind of element it is
> and use the proper child/children properties. For example a Panel has its
> children in the Children property which you may use to add/remove children.
> The Adorner classes use a single Child property. You need to look at what
> Window exposes for managing the children in your case and code to that.
> Also note that the collection under an enumeration may not be modified
> during the enumeration, so even had it been possible to do what you had, it
> would blow up when the enumeration attempted to access elements after the
> remove operation. This sometimes means that you need to create a temporary
> collection to hold elements that are to be removed/added while iterating
> over the children of an element.
>
> Michael
> (C# / WPF MVP)
>
>
> "Jason Dolinger" <jdolinger@lab49.com> wrote in message
> news:%23dZkPkKGGHA.1388@TK2MSFTNGP11.phx.gbl...
>
>>Last question for the day (today has been a doozy!):
>>
>>Has anyone successfully used FrameworkElement.RemoveLogicalChild(object
>>child)? I'm attempting to insert a new object into the Logical Tree,
>>right in between the Window and the next level down (which is whatever
>>you've defined at the top level of your tree). The first step of this
>>process is removing that next level down element from the window's logical
>>tree, using the following approach (this code is in the window.cs file):
>>
>>// get the enumerator to the Window's logical children
>>IEnumerator children = this.LogicalChildren;
>>
>>// move the first spot in the collection
>>children.MoveNext();
>>
>>// Get the first element in the enumeration,
>>// this should be the first element below the window
>>FrameworkElement topLevelLogicalChild = (FrameworkElement)
>>children.Current;
>>
>>// remove the child from the window's logical tree
>>this.RemoveLogicalChild(topLevelLogicalChild);
>>
>>
>>
>>When I execute this code, the logical tree remains unchanged. While
>>debugging, I've also verified that what I get back from children.Current
>>is indeed the element that I want to remove. Most likely I'm doing
>>something wrong here, but perhaps there is a small bug this part of the
>>API? I wouldn't think that it'd be used all that much.
>>
>>Thanks for any information on this,
>>Jason
>>
>>
>>

>
>
>

Old 01-31-2006   #4 (permalink)
Michael Latta
Guest


 

Re: Does FrameworkElement.RemoveLogicalChild(object child) work?

You are trying to use much too low level an API to do this. Just set the
window's Content property to what you want for its contents.

Michael


"Jason Dolinger" <jdolinger@lab49.com> wrote in message
news:eGz6eHuGGHA.2444@TK2MSFTNGP11.phx.gbl...
> Hmm... I think I understand what you are getting at, but the Windows SDK
> doc clearly says for FrameworkElement.RemoveLogicalChild():
>
> Removes the provided element from this element's logical tree.
>
> I also just saw the ChangeLogicalParent() method. Am I to assume that
> this also exhibits the behaviour that you describe?
>
> If what you are saying is true, then what do I really need to do to insert
> a new element right underneath the window in the logical tree? The
> LogicalChildren property only has a get on it, and returns an IEnumerator.
> That essentially means that there is no way to control the logical
> children except through API methods provided which apparently don't work.
> Is this something that I just shouldn't be doing and MS doesn't want us to
> do?
>
> To give you some context, I'm still trying to find a way to be able to
> scale a borderless window up and down (This is one of 3 approaches that
> I'm trying now, blocked on all 3!). I've found that if you used a
> viewbox, the windows scales up and down nicely. However, I don't want to
> use a viewbox all of the time, as I don't always want my content to be
> scaled to the window size. So my idea was to programatically insert a
> viewbox in the logical tree at the point that I want to zoom the window
> down. Later when zooming it back up, I'd programatically remove the
> ViewBox from the tree.
>
> Does this sound crazy?
>
> Thanks Michael!
> Jason
>
>
> Michael Latta wrote:
>> The calls you are using are for managing the logical tree from within a
>> component. They exist mostly to notify some parts of the system that you
>> have already removed/added children to the tree. They do not perform the
>> add/remove. The management of children for the tree is the
>> responsibility of each element class, and in the WPF provided elements
>> this is mostly at the leaves not the common abstract classes. There is
>> no single call to make to add/remove from the tree. You need to test
>> what kind of element it is and use the proper child/children properties.
>> For example a Panel has its children in the Children property which you
>> may use to add/remove children. The Adorner classes use a single Child
>> property. You need to look at what Window exposes for managing the
>> children in your case and code to that. Also note that the collection
>> under an enumeration may not be modified during the enumeration, so even
>> had it been possible to do what you had, it would blow up when the
>> enumeration attempted to access elements after the remove operation.
>> This sometimes means that you need to create a temporary collection to
>> hold elements that are to be removed/added while iterating over the
>> children of an element.
>>
>> Michael
>> (C# / WPF MVP)
>>
>>
>> "Jason Dolinger" <jdolinger@lab49.com> wrote in message
>> news:%23dZkPkKGGHA.1388@TK2MSFTNGP11.phx.gbl...
>>
>>>Last question for the day (today has been a doozy!):
>>>
>>>Has anyone successfully used FrameworkElement.RemoveLogicalChild(object
>>>child)? I'm attempting to insert a new object into the Logical Tree,
>>>right in between the Window and the next level down (which is whatever
>>>you've defined at the top level of your tree). The first step of this
>>>process is removing that next level down element from the window's
>>>logical tree, using the following approach (this code is in the window.cs
>>>file):
>>>
>>>// get the enumerator to the Window's logical children
>>>IEnumerator children = this.LogicalChildren;
>>>
>>>// move the first spot in the collection
>>>children.MoveNext();
>>>
>>>// Get the first element in the enumeration,
>>>// this should be the first element below the window
>>>FrameworkElement topLevelLogicalChild = (FrameworkElement)
>>>children.Current;
>>>
>>>// remove the child from the window's logical tree
>>>this.RemoveLogicalChild(topLevelLogicalChild);
>>>
>>>
>>>
>>>When I execute this code, the logical tree remains unchanged. While
>>>debugging, I've also verified that what I get back from children.Current
>>>is indeed the element that I want to remove. Most likely I'm doing
>>>something wrong here, but perhaps there is a small bug this part of the
>>>API? I wouldn't think that it'd be used all that much.
>>>
>>>Thanks for any information on this,
>>>Jason
>>>
>>>
>>>

>>
>>


Closed Thread

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Does tee-object work? Sammy M. PowerShell 3 06-05-2007 07:50 PM
Compare-object doesn't seem to work with Arrays Chris Harris PowerShell 4 05-31-2007 12:38 PM
Wil this COM object work? Marco Shaw PowerShell 0 03-22-2007 01:56 PM
Adding canonical aliases for Compare-Object, Measure-Object, New-Object Alex K. Angelopoulos [MVP] PowerShell 2 05-26-2006 07:58 AM
Binding to same DP on another instance of same object won't work. Marcus Avalon 0 03-15-2006 10:21 PM








Vistax64.com is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media 2005-2008

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50