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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T20:07:16+00:00 2026-05-12T20:07:16+00:00

I have a set of controls bound to data, on which I would like

  • 0

I have a set of controls bound to data, on which I would like to programmaticaly add validators to the bindings. Currently I’m able to iterate over the visual tree to find those controls with bindings, and also add my validators to these controls. But to further specify which controls should have specific validation I wanted to use styles. So my XAML looks like this:

<TextBox Name="someTextBox" Style="{StaticResource optionalNumericTextBox}" />

Here, the optionalNumericTextBox style serves both adding a validation error template and as a decorator to indicate that this textbox should have the optional numeric validator applied.

The problem occurs when I’m traversing the visual tree, discovers a control with bindings, and then need to determine the style in use. Currently I’ve tried

dependencyObject.GetValue(FrameworkElement.StyleProperty)

which gives me a Style object but as far as I can tell, this object does not carry the
‘optionalNumericTextBox’ value. Is it even possible to determine the key or is this information lost in the XAML reader?

  • 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-12T20:07:17+00:00Added an answer on May 12, 2026 at 8:07 pm

    When using StaticResourceExtension, this information is lost at compile time when converting your XAML to BAML. Using DynamicResourceExtension, on the other hand, keeps the key around so the resource can be resolved at runtime. To get at the key, you’ll need to use ReadLocalValue():

    //this gets the Style
    var s = textbox.GetValue(TextBox.StyleProperty);
    //this gets a ResourceReferenceExpression
    var l = textbox.ReadLocalValue(TextBox.StyleProperty);
    

    The problem is, ResourceReferenceExpression is an internal type, so you’ll need to use reflection to pull out the key.

    As an alternative to all this, have you considered hijacking the Tag property instead?

    <Style x:Key="optionalNumericTextBox" TargetType="TextBox">
        <Setter Property="Tag" Value="optionalNumericTextBox"/>
    </Style>
    

    Then your code can simply check the Tag property on the TextBox.

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

Sidebar

Related Questions

I have a data bound GridView control, in which I am able to disable
If a set of controls on a WinForm have had DataBindings created and attached
I have a list of items on a page with a set of controls
I have java script code to set some of the properties of ajax controls.
I have UserControls containing other controls. I want that if I set a Foreground
I have 4 numeric up down controls on a form. They are set to
I am using Telerik WinForms RadGridView Control, I have set up Excel-like filtering, everything
I have a UserControl that I want to participate in data binding. I've set
I'm planning a WPF application which will be able to create dynamic data entry
I have a data bound tab control: <TabControl ItemsSource={Binding Products} Name=ProductsTabControl> <TabControl.ItemTemplate> <DataTemplate> <TextBlock

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.