Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
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.

Go Back   Vista Forums > Misc Newsgroups > Avalon

Vista - FindResource problem( Reusing Drawings )

 
 
Old 09-06-2006   #1 (permalink)
Adam Smith [MS]


 
 

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


 
 

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]


 
 

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]


 
 

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
 

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


Vista Forums 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 Ltd

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