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 - Styles on Ellipses

 
 
Old 01-10-2006   #1 (permalink)
CSkinner


 
 

Styles on Ellipses

Why does the following XAML not end up setting the event values on the lone
Ellipse declared in the body of the canvas? I know this as I'm not breaking
in the event handlers. Also, if I change the TargetType on the style to be
Ellipse, I get a

"Error at element 'Setter' in markup file 'example4.xaml' : The property
'MouseDown' is not a DependencyProperty on the Style's TargetType class
'System.Windows.Shapes.Ellipse'. Verify the TargetType of the Style, or use
Class.Property syntax to specify the property.."

This makes sense, but why does it work with Shape?

Thanks,

CS

<Window x:Class="GraphicsExamples.Example4"

xmlns="http://schemas.microsoft.com/winfx/avalon/2005"

xmlns:x="http://schemas.microsoft.com/winfx/xaml/2005"

Title="Change Item"

Width="300" Height="200"

>


<Window.Resources>

<Style TargetType="{x:Type Ellipse}">

<Setter Property="MouseDown" Value="OnMouseDown" />

<Setter Property="MouseMove" Value="OnMouseMove" />

<Setter Property="MouseUp" Value="OnMouseUp" />

</Style>

</Window.Resources>

<Canvas Name="mCanvas">

<Ellipse Name="mYellow" Canvas.Left="50" Canvas.Top="70" Fill="Yellow"

Width="40" Height="20" />

</Canvas>

</Window>



My System SpecsSystem Spec
Old 01-10-2006   #2 (permalink)
CSkinner


 
 

Re: Styles on Ellipses

Nice! The EventSetter did the trick. Thanks Michael!


"Michael Latta" <lattam@mac.com> wrote in message
news:eK2hRm1%23FHA.1028@TK2MSFTNGP11.phx.gbl...
>I suggest 2 things:
>
> 1) Look at EventSetter to set event bindings in a style.
> 2) Think about using the dependency properties like IsMouseOver and
> IsMouseDirectlyOver. Unfortunately there is no property for IsMouseDown,
> though you could create a subclass of Ellipse that has that property.
>
> Michael
>
>
> "Doug" <doug@remove.11011.net> wrote in message
> news:eca9ec38d15d28c7c97b12c20bf0@news.microsoft.com...
>> Unfortunately you can't bind event handlers the same way you bind
>> dependency properties. I think being able to write <Button
>> Click="OnClick" /> is special cased by the XAML parser.
>>
>> In this case, even if it was a Dependency Property of some delegate type,
>> I think it would be very difficult for the WPF runtime to locate a method
>> in your codebehind for a given string.
>>
>> I assume the reason it works (doesn't raise an exception) for Shape is
>> because you dont have any Shape elements, you have subclasses of shape,
>> but styles are applied only to the exact runtime type. The setters for
>> the style are never applied to any of your elements when you specify
>> {x:type Shape} so nothing actually goes wrong.
>>
>> Can you perhaps use routed events to trigger what happens in your event
>> handlers?
>>
>> - Doug
>>
>>
>>> Why does the following XAML not end up setting the event values on the
>>> lone Ellipse declared in the body of the canvas? I know this as I'm
>>> not breaking in the event handlers. Also, if I change the TargetType
>>> on the style to be Ellipse, I get a
>>>
>>> "Error at element 'Setter' in markup file 'example4.xaml' : The
>>> property 'MouseDown' is not a DependencyProperty on the Style's
>>> TargetType class 'System.Windows.Shapes.Ellipse'. Verify the
>>> TargetType of the Style, or use Class.Property syntax to specify the
>>> property.."
>>>
>>> This makes sense, but why does it work with Shape?
>>>
>>> Thanks,
>>>
>>> CS
>>>
>>> <Window x:Class="GraphicsExamples.Example4"
>>>
>>> xmlns="http://schemas.microsoft.com/winfx/avalon/2005"
>>>
>>> xmlns:x="http://schemas.microsoft.com/winfx/xaml/2005"
>>>
>>> Title="Change Item"
>>>
>>> Width="300" Height="200"
>>>
>>> <Window.Resources>
>>>
>>> <Style TargetType="{x:Type Ellipse}">
>>>
>>> <Setter Property="MouseDown" Value="OnMouseDown" />
>>>
>>> <Setter Property="MouseMove" Value="OnMouseMove" />
>>>
>>> <Setter Property="MouseUp" Value="OnMouseUp" />
>>>
>>> </Style>
>>>
>>> </Window.Resources>
>>>
>>> <Canvas Name="mCanvas">
>>>
>>> <Ellipse Name="mYellow" Canvas.Left="50" Canvas.Top="70"
>>> Fill="Yellow"
>>>
>>> Width="40" Height="20" />
>>>
>>> </Canvas>
>>>
>>> </Window>
>>>

>>
>>

>
>



My System SpecsSystem Spec
 

Thread Tools


Similar Threads
Thread Forum
Templates/Styles .NET General
Visual Styles Vista General
Everything has ellipses..... PowerShell
DVD Maker Menu Styles... Vista music pictures video


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