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 7650873
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T11:21:53+00:00 2026-05-31T11:21:53+00:00

I tried following code but it gave null reference error for second line. I

  • 0

I tried following code but it gave null reference error for second line. I deleted second line but now it gave same error for third line. Any idea?

Binding binding = BindingOperations.GetBinding(txt_density, TextBox.TextProperty);
binding.ValidationRules.Clear();
binding.ValidationRules.Add(new MainWindow.Float_Positive_ValidationRule());
  • 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-31T11:21:55+00:00Added an answer on May 31, 2026 at 11:21 am

    You haven’t included the relevant XAML so it is hard to say definitively what the issue is.

    If you set a break point on the line binding.ValidationRules.Clear(); you will most likely find your binding is null, probably because there has been no binding set on the Text property.

    If there is a valid binding set on the property then the ValidationRules collection should be initialised but empty (i.e. not null), so this shouldn’t be your problem, which leaves the binding itself as the problem.

    If you use this simple example you will see what I mean, just remove the Text binding from the XAML to cause the error.

    <Window x:Class="WpfApplication1.MainWindow"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            Title="MainWindow" Height="350" Width="525">
        <Grid>
            <TextBox x:Name="txt_density" Text="{Binding SomeText}"  />
        </Grid>
    </Window>
    
    
    namespace WpfApplication1
    {
        /// <summary>
        /// Interaction logic for MainWindow.xaml
        /// </summary>
        public partial class MainWindow : Window
        {
            public MainWindow()
            {
                InitializeComponent();
    
                SomeText = "blah";
                this.DataContext = this;
                this.Loaded += new RoutedEventHandler(MainWindow_Loaded);
            }
    
            void MainWindow_Loaded(object sender, RoutedEventArgs e)
            {
                Binding binding = BindingOperations.GetBinding(txt_density, TextBox.TextProperty);
                binding.ValidationRules.Clear();
                //binding.ValidationRules.Add(new MainWindow.Float_Positive_ValidationRule());
            }
    
            public string SomeText { get; set; }
    
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have tried the following code but has no effect: Imports system.Runtime.InteropServices <DllImport(UxTheme.DLL, BestFitMapping:=False,
I tried to control email address and reviewer's name with the following code but
How can I iterate ResultSet ? I've tried with the following code, but i
I tried following some of the code from here and here , but I
I have tried for unload and beforeunload binding in following code, but none of
I tried the following code. Although I don't get any errors, it did not
I tried putting the following code into a program yesterday. VBA called an error.
My friend gave the following code which is working awesome here http://jsfiddle.net/WVLE2/ I tried
I want to get script's origin filename in global functions. I tried following code,
I tried the following code from w3schools. When I enter letters in a input

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.