WPF Style Override breaks Validation Error event propagation

Posted by Ben McMillan on Stack Overflow See other posts from Stack Overflow or by Ben McMillan
Published on 2010-03-26T20:41:14Z Indexed on 2010/03/26 20:43 UTC
Read the original article Hit count: 563

I have a custom control that overrides Window:

public class Window : System.Windows.Window
{
    static Window()
    {
        DefaultStyleKeyProperty.OverrideMetadata(typeof(Window), new System.Windows.FrameworkPropertyMetadata(typeof(Window)));                        
    }
    ...
}

It also has a style:

<Style TargetType="{x:Type Controls:Window}" BasedOn="{StaticResource {x:Type Window}}">
    <Setter Property="WindowStyle"
            Value="None" />        
    <Setter Property="Padding"
            Value="5" />
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type Controls:Window}">
 ...

Unfortunately, this breaks the propagation of the Validation.ErrorEvent for my window's contents. That is, my window can receive the event just fine, but I don't know what to do with it to mimic how a standard Window (or whoever) deals with it.

If the validating controls are placed in a standard window, they work. They also work if I just take out the OverrideMetadata call (leaving them inside my custom window).

Why is this happening, and how can I get the stock functionality for handling these validation error events working again?

Thanks!

© Stack Overflow or respective owner

Related posts about wpf

Related posts about validation