Windows Vista Forums
Vista Forums Home Join Vista Forums Webcasts 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

Styles on Ellipses

Update your Vista Drivers Update Your Drivers Now!!
Closed Thread
 
Thread Tools Display Modes
Old 01-10-2006   #1 (permalink)
CSkinner
Guest


 

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)
Doug
Guest


 

Re: Styles on Ellipses

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
Old 01-10-2006   #3 (permalink)
Michael Latta
Guest


 

Re: Styles on Ellipses

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
Old 01-10-2006   #4 (permalink)
CSkinner
Guest


 

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
Closed Thread

Thread Tools
Display Modes



Similar Threads
Thread Thread Starter Forum Replies Last Post
Visual Styles Meaghan Vista General 3 06-13-2008 06:09 PM
PLEASE --- Visual Styles for Vista Gabriel Vista General 5 10-24-2007 05:50 AM
Everything has ellipses..... ryanlsanders@gmail.com PowerShell 2 05-16-2007 02:33 PM
Viewing styles in the January CTP Keith Patrick Avalon 4 01-31-2006 06:59 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