Ujjwal27
Ujjwal27

Reputation: 1153

Set Dependency Property Value in Event Trigger of XAML?

I am trying to set the value for one of the dependency property in the Event Trigger. Unable to achieve this in Styles.

The below mentioned style in the code is for my DataGridCell, so when some Drop event occurs on the DataGridCell i would like to set the property value to True for depedency property "dragdrop:DragDropHelper.HighlightColumn".

I would need some thing like below.

<Style x:Key="GridCellStyle" TargetType="DataGridCell">
    <Setter Property="FontFamily" Value="Verdana"></Setter>                    
    <Style.Triggers>
        <Trigger Property="IsSelected" Value="True">
            <Setter Property="Background" Value="Beige"></Setter>
            <Setter Property="Foreground" Value="Black"></Setter>
        </Trigger>
        <EventTrigger RoutedEvent="Drop">
            <Setter Property="dragdrop:DragDropHelper.HighlightColumn" Value="True"></Setter>
        </EventTrigger>
    </Style.Triggers>
</Style>

Upvotes: 0

Views: 1261

Answers (1)

Clemens
Clemens

Reputation: 128099

You can't add a Setter to an EventTrigger. Use an appropriate BeginStoryboard action like this:

<EventTrigger RoutedEvent="Drop">
    <BeginStoryboard>
        <Storyboard>
            <BooleanAnimationUsingKeyFrames
                Storyboard.TargetProperty="(dragdrop:DragDropHelper.HighlightColumn)">
                <DiscreteBooleanKeyFrame KeyTime="0:0:0" Value="True"/>
            </BooleanAnimationUsingKeyFrames>
        </Storyboard>
    </BeginStoryboard>
</EventTrigger>

Upvotes: 1

Related Questions