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

  • SEARCH
  • Home
  • 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 7919671
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T15:56:35+00:00 2026-06-03T15:56:35+00:00

I want to display the errors (IDataErrorInfo.Errors) in One place of screen instead of

  • 0

I want to display the errors (IDataErrorInfo.Errors) in One place of screen instead of showing Error Content near by.. So For that I have placed textBlock in End of the Form.. How Can I Get Current Focused Element for Binding (Validation.Errors)[0].ErrorContent.

this should be done in XAML not in Code behind.

When Focus Changed then That Element’s Error content is displayed in that TextBlock placed bottom of the screen..

Thanks & Regards
Dineshbabu Sengottian

  • 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-06-03T15:56:37+00:00Added an answer on June 3, 2026 at 3:56 pm

    You can access the focused element using FocusManager.FocusedElement. Here is an example that works purely with XAML, without any code-behind (except of course for the code-behind necessary to provide IDataErrorInfo errors for testing):

    <Window x:Class="ValidationTest.MainWindow"
            x:Name="w"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            Title="MainWindow" Height="350" Width="525">
    
        <StackPanel>
            <TextBox x:Name="txt1" Text="{Binding Path=Value1, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True, Mode=TwoWay}"/>
            <TextBox x:Name="txt2" Text="{Binding Path=Value2, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True, Mode=TwoWay}"/>
            <TextBlock Foreground="Red" Text="{Binding 
                            RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, 
                            Path=(FocusManager.FocusedElement).(Validation.Errors)[0].ErrorContent}"/>
        </StackPanel>
    </Window>
    

    The test class MainWindow has the following code:

    namespace ValidationTest
    {
        public partial class MainWindow : Window, IDataErrorInfo
        {
            public MainWindow()
            {
                InitializeComponent();
    
                DataContext = this;
    
                Value1 = "a";
                Value2 = "b";
            }
    
            public string Value1 { get; set; }
            public string Value2 { get; set; }
    
            #region IDataErrorInfo Members
    
            public string Error
            {
                get { return ""; }
            }
    
            public string this[string name]
            {
                get
                {
                    if (name == "Value1" && Value1 == "x")
                    {
                        return "Value 1 must not be x";
                    }
                    else if (name == "Value2" && Value2 == "y")
                    {
                        return "Value 2 must not be y";
                    }
                    return "";
                }
            }
    
            #endregion
        }
    }
    

    For testing, you get a validation error if you put “x” in the first text box or if you put “y” in the second text box.

    The error message of the currently focused text box appears below the two text boxes in the TextBlock.

    Please note that this solution has one drawback. If you run the sample under the debugger, you will see those binding errors:

    System.Windows.Data Error: 17 : Cannot get ‘Item[]’ value (type ‘ValidationError’) from ‘(Validation.Errors)’ (type ‘ReadOnlyObservableCollection`1′). BindingExpression:Path=(0).(1)[0].ErrorContent; DataItem=’MainWindow’ (Name=’w’); target element is ‘TextBlock’ (Name=”); target property is ‘Text’ (type ‘String’) ArgumentOutOfRangeException:’System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values.

    These debug error messages occur when the currently focused element has not validation error, because the Validation.Errors array is empty, and therefore [0] is illegal.

    You can choose either to ignore those error messages (the sample still runs fine), or you need some code-behind nevertheless, e.g. a converter that converts the IInputElement returned from FocusManager.FocusedElement to a string.

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

Sidebar

Related Questions

I want to display script errors in a popup alert instead of showing them
I don't want to display errors in a screen, except that I want to
I have a multi-lingual page where I want to display form validation error in
I have a jQuery function that is causing display errors in IE7. I simply
I have a form and I want to display the errors in a for
I have a simple quiz application and I want display a nice timer /
I have db with this table (TableToDo): http://goo.gl/NlTEk I want display all records in
I want to display error messages in my view. What is the best way
I have iframe based facebook app, I just want to do is that whenever
I am calling methods on WMI/WBEM interfaces that return HRESULTS. I want to display

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.