Boardy
Boardy

Reputation: 36237

Perform Event Trigger on DataGrid for DragEnter causing XAML exception

I am working on a c# wpf project and I have run in to a problem relating to firing an trigger within the XAML.

What I am trying to achieve is when the drags a file into the grid, it should animate the background colour change but for some reason it keeps on throwing an exception as soon as I run the program. I am getting the following error:

'Provide value on 'System.Windows.Baml2006.TypeConverterMarkupExtension' threw an exception.' Line number '9' and line position '14'.

Below is the XAML code

<UserControl x:Class="ReportReader.UserControls.ReportDragDropControl"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008">
    <Grid AllowDrop="True" DragDrop.DragOver="Grid_DragOver"
          DragDrop.DragEnter="Grid_DragEnter" DragDrop.Drop="Grid_Drop" DragDrop.DragLeave="Grid_DragLeave">
        <Grid.Triggers>
            <EventTrigger RoutedEvent="Grid.DragEnter">
                <BeginStoryboard>
                    <Storyboard>
                        <ColorAnimation To="#cecece" Storyboard.TargetProperty="(Grid.BackgroundColor).(SolidColorBrush.Color)" FillBehavior="Stop" Duration="0.0.1" />    
                    </Storyboard>
                </BeginStoryboard>
            </EventTrigger>
        </Grid.Triggers>
        <TextBlock Margin="12,12,20,12" Name="txtDragDropStatus" Text="Drag file here or use file menu to load your report" TextAlignment="Center" FontSize="30" FontWeight="Bold" TextWrapping="WrapWithOverflow" Width="835" HorizontalAlignment="Center" VerticalAlignment="Center" />
    </Grid>
</UserControl>

Thanks for any help you can provide.

Upvotes: 1

Views: 1575

Answers (1)

Rohit Vats
Rohit Vats

Reputation: 81323

There are two errors in your XAML file -

  1. BackgroundColor is not a Dependency Property, instead use Background.
  2. 0.0.1 is not a valid value for TimeSpan. It should be 0:0:1.

This will work fine -

<ColorAnimation To="#cecece"
                Storyboard.TargetProperty="(Grid.Background)
                                            .(SolidColorBrush.Color)"
                FillBehavior="Stop" Duration="0:0:1" />

Also, to allow animation on background property, you should set it to some default value.

<Grid Background="White"/>

I tried with this sample and its working fine on drag enter -

<Grid AllowDrop="True" Background="White" DragDrop.DragEnter="Grid_DragEnter">
    <Grid.Triggers>
        <EventTrigger RoutedEvent="Grid.DragEnter">
            <BeginStoryboard>
                <Storyboard>
                   <ColorAnimation To="#cecece"
                                   Storyboard.TargetProperty="(Grid.Background).
                                                     (SolidColorBrush.Color)" 
                                   FillBehavior="Stop" Duration="0:0:1" />
                 </Storyboard>
            </BeginStoryboard>
         /EventTrigger>
     </Grid.Triggers>
     <TextBlock Margin="12,12,20,12" Name="txtDragDropStatus"
                Text="Drag file here or use file menu to load your report"/>
</Grid>

Upvotes: 1

Related Questions