![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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. |
| |||||||
| |
| | #1 (permalink) |
| | How to add handler or listen to a change of dependency property Dear all I want to implement "BitmapButton" derived from Button BitmapButtons have 4 images for each state(normal, pressed, disabled, and mouseOver) It's proper to use ControlTemplate to customize and add Triggers. But I can't use TemplateBinding in Triggers' Setter ( I need to template binding a dependency property in MouseOver trigger i.e. change image source) So I find other way to do that. I want to listen the UIElement.IsMouseOver property change? And write code to change bitmap. firstly, I use DependencyProperty.OverrideMetadata to new a metadata with my PropertyChangedCallback. But I got a exception which says that I have no authroization key to override. does anyone know how to implement it? Thanks :-) |
My System Specs![]() |
| | #2 (permalink) |
| | RE: How to add handler or listen to a change of dependency property Maybe you can use OnMouseEnter/Leave events? -- Valentin Iliescu [MVP - Client Application Development] "HolaMan" wrote: > Dear all > > I want to implement "BitmapButton" derived from Button > BitmapButtons have 4 images for each state(normal, pressed, disabled, > and mouseOver) > > It's proper to use ControlTemplate to customize and add Triggers. > But I can't use TemplateBinding in Triggers' Setter > ( I need to template binding a dependency property in MouseOver trigger > i.e. change image source) > > So I find other way to do that. > I want to listen the UIElement.IsMouseOver property change? > And write code to change bitmap. > > firstly, I use DependencyProperty.OverrideMetadata to new a metadata > with my PropertyChangedCallback. > But I got a exception which says that I have no authroization key to > override. > > does anyone know how to implement it? > Thanks :-) > > |
My System Specs![]() |
| | #3 (permalink) |
| | Re: How to add handler or listen to a change of dependency property Dear villiescu Thanks for your reply. Indeed I have used this method and it works. But I just curious about the trigger mechanism and want to make code shorter and easier :-) Thanks |
My System Specs![]() |
| | #4 (permalink) |
| | Re: How to add handler or listen to a change of dependency property you could try adding a DataTrigger in your ControlTemplate`s Triggers... <ControlTemplate> <ControlTemplate.Triggers> <DataTrigger Binding={IsMouseOver} Value="True"> <Setter TargetName="MyImage" Property="Source" Value="{StaticResource MouseOverImage}" /> </DataTrigger> </ControlTemplate.Triggers> </ControlTemplate> I have used DataTriggers a large number of times.... (Although not in this particular one) and it made the job for me... HTH Marcus |
My System Specs![]() |
| | #5 (permalink) |
| | Re: How to add handler or listen to a change of dependency property Thanks you very much, Marcus I will try it ![]() |
My System Specs![]() |
| | #6 (permalink) |
| | Re: How to add handler or listen to a change of dependency property While re-reading the thread... I noticed an error in my own post... the Binding member of the DataTrigger should have been "{Binding IsMouseOver}"... Hope this did not cause any confusion!!! |
My System Specs![]() |
| | #7 (permalink) |
| | RE: How to add handler or listen to a change of dependency property You cannot use TemplateBinding in the Triggers' Setter but can you try to use Binding like this to see if it works: <Setter TargetName="myImage" Property="Source" Value="{Binding Path=MouseOverImageSource,RelativeSource={RelativeSource TemplatedParent}}" /> -- Valentin Iliescu [MVP - Client Application Development] "HolaMan" wrote: > Dear all > > I want to implement "BitmapButton" derived from Button > BitmapButtons have 4 images for each state(normal, pressed, disabled, > and mouseOver) > > It's proper to use ControlTemplate to customize and add Triggers. > But I can't use TemplateBinding in Triggers' Setter > ( I need to template binding a dependency property in MouseOver trigger > i.e. change image source) > > So I find other way to do that. > I want to listen the UIElement.IsMouseOver property change? > And write code to change bitmap. > > firstly, I use DependencyProperty.OverrideMetadata to new a metadata > with my PropertyChangedCallback. > But I got a exception which says that I have no authroization key to > override. > > does anyone know how to implement it? > Thanks :-) > > |
My System Specs![]() |
| | #8 (permalink) |
| | RE: How to add handler or listen to a change of dependency property Sorry, instead of TemplatedParent should be Self. <Setter TargetName="myImage" Property="Source" Value="{Binding Path=MouseOverImageSource,RelativeSource={RelativeSource Self}}" /> -- Valentin Iliescu [MVP - Client Application Development] "HolaMan" wrote: > Dear all > > I want to implement "BitmapButton" derived from Button > BitmapButtons have 4 images for each state(normal, pressed, disabled, > and mouseOver) > > It's proper to use ControlTemplate to customize and add Triggers. > But I can't use TemplateBinding in Triggers' Setter > ( I need to template binding a dependency property in MouseOver trigger > i.e. change image source) > > So I find other way to do that. > I want to listen the UIElement.IsMouseOver property change? > And write code to change bitmap. > > firstly, I use DependencyProperty.OverrideMetadata to new a metadata > with my PropertyChangedCallback. > But I got a exception which says that I have no authroization key to > override. > > does anyone know how to implement it? > Thanks :-) > > |
My System Specs![]() |
| | #9 (permalink) |
| | Re: How to add handler or listen to a change of dependency property Dear viliescu I have use Self or TemplatedParent and TemplatedParent works. Thanks you very much. |
My System Specs![]() |
| | #10 (permalink) |
| | Re: How to add handler or listen to a change of dependency property Dear viliescu I have used Self or TemplatedParent and TemplatedParent works. Thanks you very much. |
My System Specs![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| WPF: Autogenerate a Private Dependency Property ? | .NET General | |||