Forums > csharp >

[WPF] why this code throws an exception


New Reply

simplydev

mOnke?

Posts: 62

Threads: 5

Joined: Oct, 2020

Reputation: 0

Posted

 <Style
				TargetType="{x:Type Button}"
				x:Key="ShadowHover">
                <Setter
					Property="Background"
					Value="#00252525" />
                <Setter
					Property="Foreground"
					Value="#FFFFFFFF" />
                <Setter
					Property="Template">
                    <Setter.Value>
                        <ControlTemplate
							TargetType="{x:Type Button}">
                            <Border
                                Name="ButtonBorder"
								CornerRadius="0"
								Background="{TemplateBinding Background}"
								BorderThickness="1">
                                <ContentPresenter
									HorizontalAlignment="Center"
									VerticalAlignment="Center" />
                      
                            </Border>
                       
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
        <Style.Triggers>
            <EventTrigger RoutedEvent="MouseEnter">
                <EventTrigger.Actions>
                    <BeginStoryboard>
                        <Storyboard AutoReverse="False">
                            <DoubleAnimation From="0" To="10" Duration="00:00:01" Storyboard.TargetProperty="(Button.Effect).(DropShadowEffect.BlurRadius)"/>
                            </Storyboard>
                            </BeginStoryboard>
                            </EventTrigger.Actions>
                            </EventTrigger>
            <EventTrigger RoutedEvent="MouseLeave">
                <EventTrigger.Actions>
                    <BeginStoryboard>
                        <Storyboard AutoReverse="False" >
                            <DoubleAnimation From="10" To="0" Duration="00:00:01" Storyboard.TargetProperty="(Button.Effect).(DropShadowEffect.BlurRadius)"/>
                        </Storyboard>
                    </BeginStoryboard>
                </EventTrigger.Actions>
            </EventTrigger>
        </Style.Triggers>
    </Style>

This code throws an exception, I already tried several things but it remains the same.

TGN UI Developer and owner of nothing

MONKE GANG YES

Posts: 121

Threads: 5

Joined: May, 2021

Reputation: 4

Replied

Pls add the error you get.

Download Delta :Gun:

Own DLL With owl hub and dark hub support

Delta (athoi21.xyz)

Posts: 243

Threads: 4

Joined: Feb, 2021

Reputation: 4

Replied

Lemme explain with my broken english

 

Oh yeah nice target property bro

If u wanna animate with shadow effect

U have To make the shadow effect in the style and name it

Then set the storyboard.targetname 

To that shadow effect name

 

 

Then make the targetproperty to BlurRadius

And yes

 

Edit: also delete un used code on the style ;-;

 

best siggy 2021

Posts: 62

Threads: 5

Joined: Oct, 2020

Reputation: 0

Replied

@OrbitRBXSystem.InvalidOperationException: 'A Storyboard tree in a Style cannot specify TargetName. Remove TargetName 'ButtonBorder'. '

aaaa why

TGN UI Developer and owner of nothing

MONKE GANG YES

Posts: 243

Threads: 4

Joined: Feb, 2021

Reputation: 4

Replied

@simplydev What? Uh There U Go.

        <Style TargetType="{x:Type Button}" x:Key="ShadowyesHover">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type Button}">
                        <Border
                            Background="{TemplateBinding Background}"
                            BorderBrush="{TemplateBinding BorderBrush}"
                            BorderThickness="{TemplateBinding BorderThickness}"
                            SnapsToDevicePixels="True">

                            <UIElement.Effect>
                                <DropShadowEffect 
                                    x:Name="shadoweffect"
                                    BlurRadius="0"
                                    ShadowDepth="0"
                                    />
                            </UIElement.Effect>
                            
                            <ContentPresenter
                                VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                                HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                RecognizesAccessKey="True"
                                Margin="{TemplateBinding Padding}"
                                />
                            
                        </Border>
                        <ControlTemplate.Triggers>
                            <EventTrigger RoutedEvent="MouseEnter">
                                <BeginStoryboard>
                                    <Storyboard>
                                        <DoubleAnimation 
                                            Duration="0:0:0.25"
                                            RepeatBehavior="1x"
                                            AutoReverse="False"
                                            FillBehavior="HoldEnd"
                                            Storyboard.TargetName="shadoweffect"
                                            Storyboard.TargetProperty="BlurRadius"
                                            To="10"/>
                                    </Storyboard>
                                </BeginStoryboard>
                            </EventTrigger>
                            <EventTrigger RoutedEvent="MouseLeave">
                                <BeginStoryboard>
                                    <Storyboard>
                                        <DoubleAnimation
                                            Duration="0:0:0.25"
                                            RepeatBehavior="1x"
                                            AutoReverse="False"
                                            FillBehavior="HoldEnd"
                                            Storyboard.TargetName="shadoweffect"
                                            Storyboard.TargetProperty="BlurRadius"/>
                                    </Storyboard>
                                </BeginStoryboard>
                            </EventTrigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

best siggy 2021

Posts: 62

Threads: 5

Joined: Oct, 2020

Reputation: 0

Replied

@OrbitRBXah thx im retarded lol

Added

@OrbitRBXah thx im retarded lol

TGN UI Developer and owner of nothing

MONKE GANG YES

Zander7473

Casual Femboy Agent

Mention

Posts: 1049

Threads: 31

Joined: Mar, 2020

Reputation: 12

Replied

You're overcomplicating it, what I do at first is set the Button's dropshadow's opacity to 0. And on the eventtriggers (mouseenter and mouseleave) I change the opacity to 100 and change the opacity to 0 for leave event. I personally don't set it in the buttons but I suggest using blend anims in the style itself. Its easier in my opinion anyway, also did u add a targetname?

modifying a ui and calling it yours doesn't mean it's your ui.

 

"I placed an extra cucumber on your sandwitch so your sandwitch is mine!" -littletimmy

Posts: 62

Threads: 5

Joined: Oct, 2020

Reputation: 0

Replied

@Zander7473thx I got the result I wanted

TGN UI Developer and owner of nothing

MONKE GANG YES


New Reply