![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
| |
| | #1 (permalink) |
| | Re: FindResource problem( Reusing Drawings ) The problem I assume you're hitting is that the Polygon already has a parent. Polygon is an Element (and a Visual) and these can be made into a tree - not a graph - meaning that each Element can only have one parent. If you wish to re-use vector content, consider using Drawings, like so: <ResourceDictionary> <GeometryDrawing x:Key="MySquare" Brush="Orange" Geometry="M0,0 L0,1 1,1 1,0 z" /> </ResourceDictionary> <Image> <Image.Source> <DrawingImage Drawing="{DynamicResource MySquare}"/> </Image.Source> </Image> .... or similarly through code. -Adam "Igor Lisbaron" <igorl@afcon.co.il> wrote in message news:uQd93Fd0GHA.4580@TK2MSFTNGP05.phx.gbl... > Hello everyone ! > > > I had defined some shape element ( Polygon for example ) > in a resourse.xaml file and want to draw it in a Canvas. > I have tried the following code, that works properly: > Polygon p = (Polygon)this.FindResource("MyPoligon"); > > this.canvas.Children.Add(p); > > > > But when I have tried to draw another one polygon using the same resource, > I had caught an exception. > > So my question is : How can I draw another one polygon from my c# code ? > > > > Igor > > > > |
My System Specs![]() |
| | #2 (permalink) |
| | FindResource problem( Reusing Drawings ) Hello everyone ! I had defined some shape element ( Polygon for example ) in a resourse.xaml file and want to draw it in a Canvas. I have tried the following code, that works properly: Polygon p = (Polygon)this.FindResource("MyPoligon"); this.canvas.Children.Add(p); But when I have tried to draw another one polygon using the same resource, I had caught an exception. So my question is : How can I draw another one polygon from my c# code ? Igor |
My System Specs![]() |
| | #3 (permalink) |
| | Re: FindResource problem( Reusing Drawings ) You can also set x:Shared="false" on the ResourceDictionary item to make it return a new instance instead of a reference to the item by default. For example: <StackPanel> <StackPanel.Resources> <Polygon x:Key="foo" x:Shared="false" Points="0 0 0 50 50 50 50 0 " Fill="Blue" Stroke="Green" StrokeThickness="10"/> </StackPanel.Resources> <StaticResource ResourceKey="foo"/> <StaticResource ResourceKey="foo"/> </StackPanel> "Igor Lisbaron" <igorl@afcon.co.il> wrote in message news:uQd93Fd0GHA.4580@TK2MSFTNGP05.phx.gbl... > Hello everyone ! > > > I had defined some shape element ( Polygon for example ) > in a resourse.xaml file and want to draw it in a Canvas. > I have tried the following code, that works properly: > Polygon p = (Polygon)this.FindResource("MyPoligon"); > > this.canvas.Children.Add(p); > > > > But when I have tried to draw another one polygon using the same resource, > I had caught an exception. > > So my question is : How can I draw another one polygon from my c# code ? > > > > Igor > > > > |
My System Specs![]() |
| | #4 (permalink) |
| | Re: FindResource problem( Reusing Drawings ) True - though you should be aware that this will not actually share the resource, which will have implications for working set. Also, this feature doesn't work in loose xaml, only complied apps. On the other hand, if you actually *want* multiple Elements, this is clearly the feature for you. -Adam Smith [MS] "Dennis Cheng [MSFT]" <dennis.cheng@online.microsoft.com> wrote in message news:usV0dLh0GHA.4476@TK2MSFTNGP05.phx.gbl... > You can also set x:Shared="false" on the ResourceDictionary item to make > it return a new instance instead of a reference to the item by default. > For example: > > <StackPanel> > <StackPanel.Resources> > <Polygon x:Key="foo" x:Shared="false" Points="0 0 0 50 50 50 50 0 > " Fill="Blue" Stroke="Green" StrokeThickness="10"/> > </StackPanel.Resources> > <StaticResource ResourceKey="foo"/> > <StaticResource ResourceKey="foo"/> > </StackPanel> > > > "Igor Lisbaron" <igorl@afcon.co.il> wrote in message > news:uQd93Fd0GHA.4580@TK2MSFTNGP05.phx.gbl... >> Hello everyone ! >> >> >> I had defined some shape element ( Polygon for example ) >> in a resourse.xaml file and want to draw it in a Canvas. >> I have tried the following code, that works properly: >> Polygon p = (Polygon)this.FindResource("MyPoligon"); >> >> this.canvas.Children.Add(p); >> >> >> >> But when I have tried to draw another one polygon using the same >> resource, I had caught an exception. >> >> So my question is : How can I draw another one polygon from my c# code ? >> >> >> >> Igor >> >> >> >> > > |
My System Specs![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| the problem with ndis.sys Blue Screen of Death problem solved? | Vista General | |||
| Re: Windows Mail Attachement Problem and Adobe Player Problem with IE8 | Vista mail | |||
| reusing cd-key? | Vista installation & setup | |||
| Reusing The Activation Key | Vista General | |||