A quick bit of DP help

1 view
Skip to first unread message

Sacha Barber

unread,
May 16, 2008, 7:37:38 AM5/16/08
to wpf-di...@googlegroups.com
Hey chaps, I need a small bit of help.

I am trying to create a Style/Template for some buttons in my app in WPF.

The button uses the Tag property to store a url for an image that gets used in the Template. I also want the Button to pulse to some scale bigger than its declared scale.

I want to use an attached property to allow the button scale to be different in different parts of my app.

So I have something like

using System.Windows;

namespace DirectPlusDemoApp
{

    public static class ButtonExtraProps
    {
        public static bool GetScaleTo(DependencyObject obj)
        {
            return (bool)obj.GetValue(ScaleToProperty);
        }

        public static void SetScaleTo(
            DependencyObject obj, bool value)
        {
            obj.SetValue(ScaleToProperty, value);
        }

        public static readonly DependencyProperty ScaleToProperty =
            DependencyProperty.RegisterAttached(
            "ScaleTo",
            typeof(double),
            typeof(ButtonExtraProps),
            new UIPropertyMetadata(1.0));
    }

}

And here is the button Style

        <Style x:Key="ButtonWithImageStyle" TargetType="{x:Type Button}">
            <Setter Property="Margin" Value="4"/>
            <Setter Property="Width" Value="25"/>
            <Setter Property="Height" Value="25"/>
            <Setter Property="Background" Value="WhiteSmoke"/>
            <Setter Property="(local:ButtonExtraProps.ScaleTo)" Value="1.0"/>
            <Setter Property="Template" Value="{StaticResource buttonWithImageTemplate}"/>
        </Style>

which uses the previously declared Template

    <ControlTemplate x:Key="buttonWithImageTemplate" TargetType="{x:Type Button}">
            <Border x:Name="border" CornerRadius="4" RenderTransformOrigin="0.5,0.5"
                    Background="{TemplateBinding Background}"
                    BorderBrush="Transparent"
                    HorizontalAlignment="Center" 
                    Width="{TemplateBinding Width}"
                    Height="{TemplateBinding Height}"
                    BorderThickness="2"  Visibility="Visible">
                <Border.RenderTransform>
                    <TransformGroup>
                        <ScaleTransform x:Name="imgScale" ScaleX="0.8" ScaleY="0.8"/>
                        <SkewTransform AngleX="0" AngleY="0"/>
                        <RotateTransform Angle="0"/>
                        <TranslateTransform X="0" Y="0"/>
                    </TransformGroup>
                </Border.RenderTransform>


                <Image Source="{Binding RelativeSource={RelativeSource TemplatedParent},
                        Path=Tag}" HorizontalAlignment="Center" VerticalAlignment="Center"
                           Margin="{TemplateBinding Padding}">
                </Image>
            </Border>
            <ControlTemplate.Triggers>
                <Trigger Property="IsEnabled" Value="false">
                    <Setter TargetName="border" Property="Opacity" Value="0.4"/>
                </Trigger>
                <Trigger Property="IsMouseOver" Value="true">
                    <Setter TargetName="border" Property="Background" Value="WhiteSmoke"/>
                    <Setter TargetName="border" Property="BorderBrush" Value="LightGray"/>
                </Trigger>
                <EventTrigger RoutedEvent="Mouse.MouseEnter">
                    <BeginStoryboard>
                        <Storyboard>
                            <DoubleAnimation Duration="0:0:0.2" Storyboard.TargetName="imgScale" 
                                             Storyboard.TargetProperty="(ScaleTransform.ScaleX)" To="1.0" AutoReverse="True"/>
                            <DoubleAnimation Duration="0:0:0.2" Storyboard.TargetName="imgScale"
                                             Storyboard.TargetProperty="(ScaleTransform.ScaleY)" To="1.0" AutoReverse="True"/>
                        </Storyboard>
                    </BeginStoryboard>
                </EventTrigger>
            </ControlTemplate.Triggers>
        </ControlTemplate>


What I want to replace is the hardcoded values of 1.0 in the MouseEnter StoryBoard.

I am decalring local NS at top of file like

    xmlns:local="clr-namespace:DirectPlusDemoApp;assembly="  

but when I try and compile I get an error with the namespace, and im not sure about the syntax for working with Attached props in story boards and Styles. Is what I am trying eevn correct. I am trying to do

                        <Setter Property="(local:ButtonExtraProps.ScaleTo)" Value="1.0"/>

in the style, which I think is ok, but what the heck do I do in the stoeyboard, I tried

                            <DoubleAnimation Duration="0:0:0.2" Storyboard.TargetName="imgScale" 
                                             Storyboard.TargetProperty="(ScaleTransform.ScaleX)" To="{TemplateBinding (local:ButtonExtraProps.ScaleTo)}" AutoReverse="True"/>

Can anyone give me some advice on this matter

Thanks







Miss your Messenger buddies when on-the-go? Get Messenger on your Mobile!

Josh Smith

unread,
May 16, 2008, 2:46:01 PM5/16/08
to wpf-di...@googlegroups.com
Sorry man. Im in an airport replying on a PDA. No laptop. Will look into this sunday night.

-----Original Message-----
From: Sacha Barber <sacha...@hotmail.com>
Sent: Friday, May 16, 2008 7:37 AM
To: wpf-di...@googlegroups.com <wpf-di...@googlegroups.com>
Subject: A quick bit of DP help

Hey chaps, I need a small bit of help.

I am trying to create a Style/Template for some buttons in my app in WPF.

The button uses the Tag property to store a url for an image that gets used in the Template. I also want the Button to pulse to some scale bigger than its declared scale.

I want to use an attached property to allow the button scale to be different in different parts of my app.

So I have something like

using System.Windows;namespace DirectPlusDemoApp{ public static class ButtonExtraProps { public static bool GetScaleTo(DependencyObject obj) { return (bool)obj.GetValue(ScaleToProperty); } public static void SetScaleTo( DependencyObject obj, bool value) { obj.SetValue(ScaleToProperty, value); } public static readonly DependencyProperty ScaleToProperty = DependencyProperty.RegisterAttached( "ScaleTo", typeof(double), typeof(ButtonExtraProps), new UIPropertyMet

[The entire original message is not included]

Marlon Grech

unread,
May 16, 2008, 4:37:01 PM5/16/08
to wpf-di...@googlegroups.com
I think the namespace should be
xmlns:local="clr-namespace:DirectPlusDemoApp"

instead of

xmlns:local="clr-namespace:DirectPlusDemoApp;assembly=" 

--
Regards
Marlon
Blog - http://marlongrech.wordpress.com/
WPF Controls Library - http://www.codeplex.com/avaloncontrolslib

Andrew

unread,
May 16, 2008, 6:02:23 PM5/16/08
to wpf-di...@googlegroups.com

You're clr get/set methods are dealing with bool but you're registering a double property.

 

-Andrew



----- Original Message ----
From: Josh Smith <flappl...@gmail.com>
To: wpf-di...@googlegroups.com
Sent: Friday, May 16, 2008 2:46:01 PM
Subject: RE: A quick bit of DP help


Sorry man.  Im in an airport replying on a PDA.  No laptop.  Will look into this sunday night.

-----Original Message-----
From: Sacha Barber <sacha...@hotmail.com>
Sent: Friday, May 16, 2008 7:37 AM
To: wpf-di...@googlegroups.com <wpf-di...@googlegroups.com>
Subject: A quick bit of DP help

Hey chaps, I need a small bit of help.

I am trying to create a Style/Template for some buttons in my app in WPF.

The button uses the Tag property to store a url for an image that gets used in the Template. I also want the Button to pulse to some scale bigger than its declared scale.

I want to use an attached property to allow the button scale to be different in different parts of my app.

So I have something like

using System.Windows;namespace DirectPlusDemoApp{    public static class ButtonExtraProps    {        public static bool GetScaleTo(DependencyObject obj)        {            return (bool)obj.GetValue(ScaleToProperty);        }        public static void SetScaleTo(            DependencyObject obj, bool value)        {            obj.SetValue(ScaleToProperty, value);        }        public static readonly DependencyProperty ScaleToProperty =            DependencyProperty.RegisterAttached(            "ScaleTo",            typeof(double),            typeof(ButtonExtraProps),            new UIPropertyMet

Sacha Barber

unread,
May 16, 2008, 2:47:30 PM5/16/08
to wpf-di...@googlegroups.com
No worries boss, going/been somewhere nice.




> From: flappl...@gmail.com
> Subject: RE: A quick bit of DP help
> Date: Fri, 16 May 2008 14:46:01 -0400
> To: wpf-di...@googlegroups.com

Josh Smith

unread,
May 16, 2008, 7:31:40 PM5/16/08
to wpf-di...@googlegroups.com
Charlotte for code camp with Karl

-----Original Message-----
From: Sacha Barber <sacha...@hotmail.com>
Sent: Friday, May 16, 2008 2:47 PM
To: wpf-di...@googlegroups.com
Subject: RE: A quick bit of DP help

No worries boss, going/been somewhere nice.

> From: flappl...@gmail.com


> Subject: RE: A quick bit of DP help
> Date: Fri, 16 May 2008 14:46:01 -0400
> To: wpf-di...@googlegroups.com
>
>
> Sorry man. Im in an airport replying on a PDA. No laptop. Will look into this sunday night.
>
> -----Original Message-----
> From: Sacha Barber <sacha...@hotmail.com>
> Sent: Friday, May 16, 2008 7:37 AM
> To: wpf-di...@googlegroups.com <wpf-di...@googlegroups.com>
> Subject: A quick bit of DP help
>
> Hey chaps, I need a small bit of help.
>

Sacha Barber

unread,
May 17, 2008, 3:41:39 AM5/17/08
to wpf-di...@googlegroups.com
Ah enjoy it man.

The 2 of you together again, thats nice, molenating and LOBing everywhere, charming




> From: flappl...@gmail.com
> Subject: RE: A quick bit of DP help
> Date: Fri, 16 May 2008 19:31:40 -0400
> To: wpf-di...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages