![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
|
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.
br> br> |
| |||||||
![]() |
| | Thread Tools | Display Modes |
| | #1 (permalink) |
| Guest | Re: Implementing z-order control of FrameworkElement children Hi Fred, Sorry for the delay. Having talked to some people, by default VisualCollection is the only class that does this "Add" and "remove" from the Visual tree automatically. Nancy "Fred Vandervelde" wrote: > Hi Nancy, > > What I'm puzzled about is the fact that I am not currently doing steps 3 and > 4 that you mention below. I am simply calling methods on my own > VisualCollection. So where changing the order the visuals are returned > through GetVisualChild does not work, simply calling methods on my own > VisualCollection causes the visual layer to be updated! What is signaling > the Visual layer that a change has been made? Again, I am not calling > AddVisualChild or RemoveVisualChild - Is the parent somehow monitoring my > child collection for changes? My changes are reflected immediately on > screen, so somehow my frameworkelement knows it needs to Render(). Changing > my child visuals brushes and/or pens also causes an immediate update to the > screen. I think it would be helpful to know what type of things cause the > visual layer to be updated, and what type of control I can have over that > process. > > Thanks, > > F. > > "Nancy Phan [MS]" <NancyPhanMS@discussions.microsoft.com> wrote in message > news:3F6DAACE-B8D5-42F0-A241-554B9127FE54@microsoft.com... > > Hi Fred, > > > > I think it's because eventhough your GetVisualChild() method correctly > > returns the inverse child order, the Visual layer is not being updated. > > When > > you call the methods VisualCollection.Remove & VisualCollection.Add, > > you'll > > also want to call Visual.RemoveVisualChild & Visual.AddVisualChild > > (respectively). Can you try this out & see if it works? This is the > > recent > > post outlining the Visual children changes & new requirements: > > > > If your tool is deriving from FrameworkElement, you'll have to maintain > > your > > own colleciton and CALL two methods to notify the Visual base class > > whenever > > your collection changes. Steps: > > > > 1. Create own child collection model (ie. VisualCollection, Visual > > _child, > > etc) > > 2. Implement > > Visual.VisualChildrenCount{get}; > > Visual.GetVisualChild(int i); > > 3. Call Visual.AddVisualChild in your own AddChild method > > 4. Call Visual.RemoveVisualChild in your own RemoveChild method > > > > Visual.AddVisualChild and Visual.RemoveVisualChild notify the Visual layer > > that a new child apear in the children collection. Your own AddChild and > > RemoveChild methods should add & remove the children from your collection > > model. > > > > > > > > > > "Fred Vandervelde" wrote: > > > >> Well, it seems I answered my own question. I'm not 100% sure why, but > >> overriding GetVisualChild does not yield the results I expected, so I > >> stopped trying to 'fake out' my FrameworkElement, and I actually modified > >> the VisualCollection. > >> > >> To manipulate the z-order for a specific visual, I ended up doing the > >> following: > >> > >> for "Bring to front": > >> > >> VisualCollection.Remove(CurrentVisual); > >> VisualCollection.Add(CurrentVisual); > >> > >> this effectively removes the visual, and re-adds it at the end of the > >> visualcollection. > >> > >> for "Send to Back" > >> > >> VisualCollection.Remove(CurrentVisual) > >> VisualCollection.Insert(0, CurrentVisual) > >> > >> this removes the visual, and re-inserts it at the beginning of the > >> VisualCollection. > >> > >> Simple. > >> > >> F. > >> > >> > >> > >> "Fred Vandervelde" <fredv AT gardengraphics DOT com> wrote in message > >> news:OfgWxLf9FHA.3208@TK2MSFTNGP11.phx.gbl... > >> > Hey everyone, > >> > > >> > I'm attempting to implement "Bring to Front" and "Send to Back" type > >> > functionality in my WPF rendering engine. I have overridden the base > >> > class' GetVisualChild() method like this: > >> > > >> > protected override Visual GetVisualChild(int index) > >> > { > >> > if(index < 0 || index > _children.Count) > >> > { > >> > throw new ArgumentOutOfRangeException(); > >> > } > >> > > >> > return (Visual)_children[_zindexmap[index]]; > >> > } > >> > > >> > In the above code, _children refers to a VisualCollection, and > >> > _zindexmap > >> > refers to an array of integers used to store the 'z-index' of each > >> > Visual. > >> > My "Bring to Front" and "Send to Back" routines then modify the > >> > _zindexmap > >> > array, which in effect changes the order in which the Visual Children > >> > are > >> > returned to the parent FrameworkElement. In the simplest example of > >> > two > >> > overlapping Visuals, "Bring to Front" correctly updates the _zindexmap > >> > so > >> > that GetVisualChild(0) returns item 1, and GetVisualChild(1) returns > >> > item > >> > 0. > >> > > >> > My problem is that I can't seem to get the visuals to update on the > >> > screen. I also change brushes for the Fill of certain Visuals - and the > >> > update to the screen is immediate. > >> > > >> > Calling InvalidateVisual() on the FrameworkElement host or the Canvas > >> > does > >> > nothing - Visual A never gets rendered 'After' Visual B. > >> > > >> > Is there something I'm missing here? Has anyone tried anything like > >> > this? > >> > > >> > Thanks in advance, > >> > > >> > Fred. > >> > > >> > > >> > > >> > > >> > > >> > >> > >> > > > |
My System Specs![]() |
| | #2 (permalink) |
| Guest | Re: Implementing z-order control of FrameworkElement children Thanks Nancy. This fact could definitely influence the design of my visual engine - nice to know! Thanks again, F. "Nancy Phan [MS]" <NancyPhanMS@discussions.microsoft.com> wrote in message news:9263D8C7-2202-46CA-807C-17DE94AAF73D@microsoft.com... > Hi Fred, > > Sorry for the delay. Having talked to some people, by default > VisualCollection is the only class that does this "Add" and "remove" from > the > Visual tree automatically. > > Nancy > > "Fred Vandervelde" wrote: > >> Hi Nancy, >> >> What I'm puzzled about is the fact that I am not currently doing steps 3 >> and >> 4 that you mention below. I am simply calling methods on my own >> VisualCollection. So where changing the order the visuals are returned >> through GetVisualChild does not work, simply calling methods on my own >> VisualCollection causes the visual layer to be updated! What is >> signaling >> the Visual layer that a change has been made? Again, I am not calling >> AddVisualChild or RemoveVisualChild - Is the parent somehow monitoring my >> child collection for changes? My changes are reflected immediately on >> screen, so somehow my frameworkelement knows it needs to Render(). >> Changing >> my child visuals brushes and/or pens also causes an immediate update to >> the >> screen. I think it would be helpful to know what type of things cause >> the >> visual layer to be updated, and what type of control I can have over that >> process. >> >> Thanks, >> >> F. >> >> "Nancy Phan [MS]" <NancyPhanMS@discussions.microsoft.com> wrote in >> message >> news:3F6DAACE-B8D5-42F0-A241-554B9127FE54@microsoft.com... >> > Hi Fred, >> > >> > I think it's because eventhough your GetVisualChild() method correctly >> > returns the inverse child order, the Visual layer is not being updated. >> > When >> > you call the methods VisualCollection.Remove & VisualCollection.Add, >> > you'll >> > also want to call Visual.RemoveVisualChild & Visual.AddVisualChild >> > (respectively). Can you try this out & see if it works? This is the >> > recent >> > post outlining the Visual children changes & new requirements: >> > >> > If your tool is deriving from FrameworkElement, you'll have to maintain >> > your >> > own colleciton and CALL two methods to notify the Visual base class >> > whenever >> > your collection changes. Steps: >> > >> > 1. Create own child collection model (ie. VisualCollection, Visual >> > _child, >> > etc) >> > 2. Implement >> > Visual.VisualChildrenCount{get}; >> > Visual.GetVisualChild(int i); >> > 3. Call Visual.AddVisualChild in your own AddChild method >> > 4. Call Visual.RemoveVisualChild in your own RemoveChild method >> > >> > Visual.AddVisualChild and Visual.RemoveVisualChild notify the Visual >> > layer >> > that a new child apear in the children collection. Your own AddChild >> > and >> > RemoveChild methods should add & remove the children from your >> > collection >> > model. >> > >> > >> > >> > >> > "Fred Vandervelde" wrote: >> > >> >> Well, it seems I answered my own question. I'm not 100% sure why, but >> >> overriding GetVisualChild does not yield the results I expected, so I >> >> stopped trying to 'fake out' my FrameworkElement, and I actually >> >> modified >> >> the VisualCollection. >> >> >> >> To manipulate the z-order for a specific visual, I ended up doing the >> >> following: >> >> >> >> for "Bring to front": >> >> >> >> VisualCollection.Remove(CurrentVisual); >> >> VisualCollection.Add(CurrentVisual); >> >> >> >> this effectively removes the visual, and re-adds it at the end of the >> >> visualcollection. >> >> >> >> for "Send to Back" >> >> >> >> VisualCollection.Remove(CurrentVisual) >> >> VisualCollection.Insert(0, CurrentVisual) >> >> >> >> this removes the visual, and re-inserts it at the beginning of the >> >> VisualCollection. >> >> >> >> Simple. >> >> >> >> F. >> >> >> >> >> >> >> >> "Fred Vandervelde" <fredv AT gardengraphics DOT com> wrote in message >> >> news:OfgWxLf9FHA.3208@TK2MSFTNGP11.phx.gbl... >> >> > Hey everyone, >> >> > >> >> > I'm attempting to implement "Bring to Front" and "Send to Back" type >> >> > functionality in my WPF rendering engine. I have overridden the >> >> > base >> >> > class' GetVisualChild() method like this: >> >> > >> >> > protected override Visual GetVisualChild(int index) >> >> > { >> >> > if(index < 0 || index > _children.Count) >> >> > { >> >> > throw new ArgumentOutOfRangeException(); >> >> > } >> >> > >> >> > return (Visual)_children[_zindexmap[index]]; >> >> > } >> >> > >> >> > In the above code, _children refers to a VisualCollection, and >> >> > _zindexmap >> >> > refers to an array of integers used to store the 'z-index' of each >> >> > Visual. >> >> > My "Bring to Front" and "Send to Back" routines then modify the >> >> > _zindexmap >> >> > array, which in effect changes the order in which the Visual >> >> > Children >> >> > are >> >> > returned to the parent FrameworkElement. In the simplest example of >> >> > two >> >> > overlapping Visuals, "Bring to Front" correctly updates the >> >> > _zindexmap >> >> > so >> >> > that GetVisualChild(0) returns item 1, and GetVisualChild(1) returns >> >> > item >> >> > 0. >> >> > >> >> > My problem is that I can't seem to get the visuals to update on the >> >> > screen. I also change brushes for the Fill of certain Visuals - and >> >> > the >> >> > update to the screen is immediate. >> >> > >> >> > Calling InvalidateVisual() on the FrameworkElement host or the >> >> > Canvas >> >> > does >> >> > nothing - Visual A never gets rendered 'After' Visual B. >> >> > >> >> > Is there something I'm missing here? Has anyone tried anything like >> >> > this? >> >> > >> >> > Thanks in advance, >> >> > >> >> > Fred. >> >> > >> >> > >> >> > >> >> > >> >> > >> >> >> >> >> >> >> >> >> |
My System Specs![]() |
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Those thieving children | MICHAEL | Vista General | 2 | 12-31-2006 12:58 PM |
| API Standards question: FrameworkElement.Focusable | Keith Patrick | Avalon | 3 | 02-27-2006 02:11 AM |
| FrameworkElement overlay notification? | Jason Dolinger | Avalon | 1 | 02-02-2006 12:50 PM |
| How to get the coordinates of a FrameworkElement? | Jason Dolinger | Avalon | 2 | 01-31-2006 07:00 AM |
| Does FrameworkElement.RemoveLogicalChild(object child) work? | Jason Dolinger | Avalon | 3 | 01-31-2006 06:59 AM |