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

FindResource problem( Reusing Drawings )

Update your Vista Drivers Update Your Drivers Now!!
Closed Thread
 
Thread Tools Display Modes
Old 09-06-2006   #1 (permalink)
Adam Smith [MS]
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 SpecsSystem Spec
Old 09-06-2006   #2 (permalink)
Igor Lisbaron
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 SpecsSystem Spec
Old 09-06-2006   #3 (permalink)
Dennis Cheng [MSFT]
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 SpecsSystem Spec
Old 09-07-2006   #4 (permalink)
Adam Smith [MS]
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 SpecsSystem Spec
Closed Thread

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


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 51