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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T10:44:01+00:00 2026-05-29T10:44:01+00:00

Within an ItemsControl which is bound to a data source, I am trying to

  • 0

Within an ItemsControl which is bound to a data source, I am trying to validate a TextBox using a custom validation rule, which accepts a parameter, following is the code for the vaildation rule.

public class RatioValidation : ValidationRule
{
    public override ValidationResult Validate(object value, System.Globalization.CultureInfo cultureInfo)
    {
        if (!String.IsNullOrEmpty(Maturity.MaturityValue) && Helper.IsDateInCorrectFormat(Maturity.MaturityValue))
        {
            String strVal = Convert.ToString(value);
            Double ratio = 0;
            Boolean isValid = Double.TryParse(strVal, out ratio);
            if (isValid)
            {
                if (ratio <= 0)
                    return new ValidationResult(false, "Please enter a valid ratio!");
                else return new ValidationResult(true, null);
            }
            return new ValidationResult(false, "Please enter a valid ratio!");
        }
        else return new ValidationResult(true, null);           
    }

    private MaturityDependencyForValidation _maturity;
    public MaturityDependencyForValidation Maturity
    {
        get { return _maturity; }
        set { _maturity = value; }
    }
}

public class MaturityDependencyForValidation : DependencyObject
{
    public String MaturityValue
    {
        get { return (String)GetValue(MaturityValueProperty); }
        set { SetValue(MaturityValueProperty, value); }
    }

    public static readonly DependencyProperty MaturityValueProperty =
        DependencyProperty.Register("MaturityValue", typeof(String), typeof(MaturityDependencyForValidation), new UIPropertyMetadata(null));

}

And then use it like following,

<TextBox Grid.Row="1" Grid.Column="2"  Name="txtRatio" BorderThickness="0" Width="148" Tag="{Binding StrMaturity, UpdateSourceTrigger=PropertyChanged}">
    <TextBox.Text>
        <Binding Path="Ratio" Mode="TwoWay"  UpdateSourceTrigger="PropertyChanged">
            <Binding.ValidationRules>
                <leg:RatioValidation ValidatesOnTargetUpdated="True">
                    <leg:RatioValidation.Maturity>
                         <leg:MaturityDependencyForValidation MaturityValue="{Binding txtMaturity}"/>
                    </leg:RatioValidation.Maturity>
                </leg:RatioValidation>
            </Binding.ValidationRules>
        </Binding>
    </TextBox.Text>
</TextBox>

I get an exception in the output window:

Cannot find governing FrameworkElement or FrameworkContentElement for target element. BindingExpression:Path=txtMaturity; DataItem=null; target element is ‘MaturityDependencyForValidation’ (HashCode=63478077); target property is ‘Maturity’ (type ‘String’)

And within the RatioValidation rule, the value of Maturity never gets bound from the data binding. I need this value for data binding. Please help.

  • 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-29T10:44:02+00:00Added an answer on May 29, 2026 at 10:44 am

    There is no DataContext as the surrounding objects, the binding at the very least, are not DependencyObjects, you are somewhat limited in your choices, it should be similar to what happens when binding in an array, also see this answer.

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

Sidebar

Related Questions

I have a Custom control in WPF in which I define a large ItemsControl
I am using an ItemsControl inside a window in WPF. The itemscontrol is bound
Within my web application, I am trying to create a directory polling bean using
Within my Subversion project I have a few directories that contain other open source
I have ObservableCollection<Foo> that is bound to an ItemsControl (basically displaying a list). Foo
Within the context of a web application written using the YUI library 3.4.1 it
Within the RelativeLayout I'm trying to figure out how to center the bottom TextView
I have a calender and I nested a itemscontrol within the calendars itemscontrol so
I have a dockpanel that I dynamically fill using an ItemsControl to populate the
I've got a custom WPF control with a DependencyProperty MyString I'm using the control

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.