![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
|
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 | 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 Specs![]() |
| | #2 (permalink) |
| 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 Specs![]() |
| | #3 (permalink) |
| 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 Specs![]() |
| | #4 (permalink) |
| 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 Specs![]() |
![]() |
| 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 |