Select to view content in your preferred language

Add form validation to ProWindow

270
1
Jump to solution
03-12-2026 06:22 AM
ShareUser
Esri Community Manager

I am trying to add form validation to a custom ProWindow in my add-in. I implemented the IDataErrorInfo interface on my viewmodel, and added a style to controls that I want to validate, e.g.

<Style TargetType="{x:Type FrameworkElement}" x:Key="ValidatingControl">
    <Style.Triggers>
        <Trigger Property="Validation.HasError" Value="True">
            <Setter Property="ToolTip" Value="{Binding Path=(Validation.Errors)[0].ErrorContent, RelativeSource={x:Static RelativeSource.Self}}" />
        </Trigger>
    </Style.Triggers>
</Style>

This adds a red border and sets a tooltip on the control if validation fails, so that all works fine.

 

But there is one thing that I haven't been able to solve: When setting the style on the control, the colors do no longer match the ArcGIS Pro theme, but revert to the default black text on grey background (for combo boxes).

I tried setting the BasedOn property on the style, and also explicitly adding Background="{DynamicResource Esri_BackgroundPressedBrush}"
Foreground="{DynamicResource Esri_TextMenuBrush}" to the style, or to the control itself, but both do not seem to do anything.

Does anyone have a working example of how to implement form validation?

0 Kudos
1 Solution

Accepted Solutions
ShareUser
Esri Community Manager

I think it's best to apply a separate style for each control type that requires validation. For example, here's a ComboBox. Keep the BasedOn so it inherits the control's default style.

    <Style x:Key="ValidatingComboBox" TargetType="ComboBox" BasedOn="{StaticResource {x:Type ComboBox}}">
      <Style.Triggers>
        <Trigger Property="Validation.HasError" Value="True">
          <Setter Property="ToolTip" 
                  Value="{Binding (Validation.Errors)[0].ErrorContent,
                  RelativeSource={RelativeSource Self}}" />
        </Trigger>
      </Style.Triggers>
    </Style>

  

View solution in original post

0 Kudos
1 Reply
ShareUser
Esri Community Manager

I think it's best to apply a separate style for each control type that requires validation. For example, here's a ComboBox. Keep the BasedOn so it inherits the control's default style.

    <Style x:Key="ValidatingComboBox" TargetType="ComboBox" BasedOn="{StaticResource {x:Type ComboBox}}">
      <Style.Triggers>
        <Trigger Property="Validation.HasError" Value="True">
          <Setter Property="ToolTip" 
                  Value="{Binding (Validation.Errors)[0].ErrorContent,
                  RelativeSource={RelativeSource Self}}" />
        </Trigger>
      </Style.Triggers>
    </Style>

  

0 Kudos