I'm having some issues with the XAML designer.

I have a UserControl which represents a custom ProgressBar: Just a rotating circle with some colors based on the state. It extends UserControl and I have added the local namespace to the XAML file and named it "local".

<UserControl x:Class="MyControls.ProgressControl"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:MyControls">

In code-behind I have created a custom event like so:

public static readonly RoutedEvent NotStartedEvent = EventManager.RegisterRoutedEvent("NotStartedEvent",RoutingStrategy.Bubble,typeof(RoutedEventHandler),typeof(ProgressControl));

// .NET wrapper
public event RoutedEventHandler NotStarted
{
    add { AddHandler(NotStartedEvent, value); }
    remove { RemoveHandler(NotStartedEvent, value); }
}

In my XAML file I have an EventTrigger to hook up some animation:

<UserControl.Triggers>
    <EventTrigger RoutedEvent="local:ProgressControl.NotStartedEvent">
        <StopStoryboard BeginStoryboardName="rotateAnimation"/>
        <BeginStoryboard Storyboard="{StaticResource notStartedStateAnimation}"/>
    </EventTrigger>
</UserControl.Triggers>

This however gives me an error: Event 'NotStartedEvent' was not found in type 'UserControl'.

I've searched the web, but couldn't find what I'm doing wrong, it must be some stupid detail. Is it for instance because the EventTrigger is under UserControl.Triggers?

I've tried cleaning and rebuilding the project several times and this works fine. Only the XAML designer is giving me this error.

有帮助吗?

解决方案

try this:

<UserControl.Triggers>
    <EventTrigger RoutedEvent="{x:Static local:ProgressControl.NotStartedEvent}">
        <StopStoryboard BeginStoryboardName="rotateAnimation"/>
        <BeginStoryboard Storyboard="{StaticResource notStartedStateAnimation}"/>
    </EventTrigger>
</UserControl.Triggers>
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top