![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
|
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: 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) |
| Guest | 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) |
| Guest | 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) |
| Guest | 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 | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Generic McAfee Problem Message in Vista Problem Reports | cyberbuff53 | Vista performance & maintenance | 0 | 12-01-2007 07:55 AM |
| reusing cd-key? | Liam Richmond | Vista installation & setup | 1 | 09-19-2007 05:25 AM |
| Reusing The Activation Key | Robert | Vista General | 6 | 02-23-2007 12:54 PM |
| Reusing a color | =?Utf-8?B?RHVxdWUgVmllaXJh?= | Avalon | 1 | 07-08-2006 02:07 PM |
| Vista Upgrade Problem - Windows Explorer Loop problem | Steve S | Vista installation & setup | 0 | 06-27-2006 10:15 AM |