Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Validation errors not displayed after applying custom window style & template (c#, WPF)

Tags:

c#

wpf

In my application resources I have the following style defined, well, I'm giving you the simplistic version (style is meant to be applied to all windows across the application):

<Style TargetType="{x:Type Window}" BasedOn="{StaticResource {x:Type Window}}">
<Setter Property="Template">
<!--Omitting irrelevant property setters-->
<Setter.Value>
 <ControlTemplate TargetType="{x:Type Window}">
  <StackPanel>
   <ContentPresenter/>
  </StackPanel>
 </ControlTemplate>
</Setter.Value>
</Setter>
</Style>

I've noticed that when this style gets applied to all windows, validation errors (IDataErrorInfo) — by means of the default red-border-box-around-control error template — aren't displayed in those windows.

What gives?

like image 714
Mikhail Avatar asked Feb 11 '26 04:02

Mikhail


1 Answers

Wrapping the window template (StackPanel in this example) into an AdornerDecorator solved this (as the decorator is used to display validation errors).

Thanks to Will, I didn't even know what to look for.

like image 138
Mikhail Avatar answered Feb 13 '26 16:02

Mikhail



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!