Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 329219
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T09:34:04+00:00 2026-05-12T09:34:04+00:00

I have implemented an error style for textboxes using the following code. This sets

  • 0

I have implemented an error style for textboxes using the following code. This sets a tool tip and puts a nice error image to the right of the textbox if the element reports an error status via an IDataErrorInfo interface:

    <!-- Set error style for textboxes -->
    <Style x:Key="txtBoxErrStyle" TargetType="{x:Type TextBox}">
        <Style.Triggers>
            <Trigger Property="Validation.HasError" Value="True">
                <Setter Property="ToolTip" 
                        Value="{Binding RelativeSource={x:Static RelativeSource.Self}, 
                        Path=(Validation.Errors)[0].ErrorContent}" />
            </Trigger>
        </Style.Triggers>

        <Setter Property="Validation.ErrorTemplate">
            <Setter.Value>
                <ControlTemplate>
                    <DockPanel DockPanel.Dock="Right">
                        <AdornedElementPlaceholder />
                        <Image Source="Icons/Error.png"
                               Height="16"
                               Width="16"
                               ToolTip="{Binding Path=AdornedElement.ToolTip, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Adorner}}}" />
                    </DockPanel>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

This works really well for me by adding the tool tip text and setting the Error.png image to the right of the textbox. But what I want to do is give similar functionality to a radio button. I attempted to do this by copying the above code and changing the tag to be:

    <!-- Set error style for radio buttons -->
    <Style x:Key="radioBtnErrStyle" TargetType="{x:Type RadioButton}">

The field that the radio button is bound to reports errors via the IDataErrorInfo interface, and the radio button itself has ValidatesOnDataErrors set to true.

This sort of worked for me. When the radio button is deemed to be in error, the tool tip is set to the error message returned from the IDataErrorInfo routine. But I cannot seem to get the Error.png image to display on the form.

I have tried some basic screwing around with the style, such as swapping the order of the and elements, but nothing I tried seemed to work.

So any ideas as to how I can get the image to display?

Update

Steffen’s reply hit the nail on the head. Increasing the margin did allow room for the image to be displayed.

However I have run into another, separate issue in that if the error condition is present when the program first starts then the tool tip will reflect the error condition, but the image will not be displayed. It is only when error condition is actively raised after the program start does the image also be displayed. I have seen this before but have not yet seen the correct way of handling it. Time to research another WPF topic!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T09:34:04+00:00Added an answer on May 12, 2026 at 9:34 am

    Given that the style seems to get applied correctly in the first place this is likely just an effect of your particular window composition, i.e. width, margin and placement of the related controls:

    Depending on your layout the image might end up behind the radio button ‘canvas’ and thus invisible, if their is not enough space left within the window to display the image alongside your control, e.g. if the RadioButton fills the entire width of a StackPanel row.

    Consequently you should be able to ‘reveal’ the image by providing enough space as you see fit, e.g. by setting an appropriate right margin of at least 16 in your case:

    <RadioButton Margin="0,0,16,0"/>
    

    According to this assumptions I’ve indeed been able to reproduce the issue: presumably it is easily overlooked because width and/or margin of a TextBox are often provided explicitly and visible either way due to the default TextBox border, while this is less common for a RadioButton and its border is invisible by default.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 177k
  • Answers 177k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Change the StackTraceDepth constant in FastMM4.pas. May 12, 2026 at 3:25 pm
  • Editorial Team
    Editorial Team added an answer stop propagation $("#Submit").click(function(event){ event.stopPropagation(); if (typeof $_submitSend == "undefined") var… May 12, 2026 at 3:25 pm
  • Editorial Team
    Editorial Team added an answer You can use the Form.DesktopLocation Property Desktop coordinates are based… May 12, 2026 at 3:25 pm

Related Questions

I have a BaseSkin and multiple UserSkins in a separate dll from my WPF
I have a question about whether or not a specific way of applying of
I have a situation where I think using the 'em' metric would be perfect.
I've been mulling over creating a language that would be extremely well suited to

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.