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 - How to add handler or listen to a change of dependency property

 
 
Old 04-19-2006   #1 (permalink)
HolaMan


 
 

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 SpecsSystem Spec
Old 04-20-2006   #2 (permalink)
viliescu


 
 

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 SpecsSystem Spec
Old 04-20-2006   #3 (permalink)
HolaMan


 
 

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 SpecsSystem Spec
Old 04-21-2006   #4 (permalink)
Marcus


 
 

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 SpecsSystem Spec
Old 04-24-2006   #5 (permalink)
HolaMan


 
 

Re: How to add handler or listen to a change of dependency property

Thanks you very much, Marcus
I will try it

My System SpecsSystem Spec
Old 04-24-2006   #6 (permalink)
Marcus


 
 

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 SpecsSystem Spec
Old 04-24-2006   #7 (permalink)
viliescu


 
 

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 SpecsSystem Spec
Old 04-24-2006   #8 (permalink)
viliescu


 
 

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 SpecsSystem Spec
Old 05-05-2006   #9 (permalink)
HolaMan


 
 

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 SpecsSystem Spec
Old 05-05-2006   #10 (permalink)
HolaMan


 
 

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 SpecsSystem Spec
 

Thread Tools


Similar Threads
Thread Forum
WPF: Autogenerate a Private Dependency Property ? .NET 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