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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T18:47:20+00:00 2026-05-17T18:47:20+00:00

I have a textbox that has the following simple XAML (not necessary to read

  • 0

I have a textbox that has the following simple XAML (not necessary to read it – just have it for reference):

<TextBox Name="m_ctrlUserDeviceType" Style="{StaticResource textStyleTextBox}" Text="{Binding Source={x:Static api:MySettings.Instance}, Path=UserDeviceType, ValidatesOnExceptions=true, NotifyOnValidationError=true}" Validation.Error="TextBox_Error" MinHeight="25" Margin="4" VerticalAlignment="Top" MaxLength="23" VerticalContentAlignment="Center" HorizontalAlignment="Left" MinWidth="100"></TextBox>

For completeness, the style textStyleTextBox looks like this (again, not necessary to read to answer question):

<Style x:Key="textStyleTextBox" TargetType="TextBox">
    <Setter Property="Foreground" Value="#333333" />
        <Setter Property="VerticalAlignment" Value="Top" />
        <Setter Property="MinHeight" Value="2" />
        <Setter Property="MinWidth" Value="100" />
        <Setter Property="Margin" Value="4" />
        <Setter Property="MaxLength" Value="23" />
        <Setter Property="VerticalContentAlignment" Value="Center" />
        <Setter Property="HorizontalAlignment" Value="Left" />
       <!-- <Setter Property="Binding Source" Value="{x:Static api:MySettings.Instance}"/>
        <Setter Property="Binding ValidatesOnExceptions" Value="true" />
        <Setter Property="Binding NotifyOnValidationError" Value="true" /> -->



  <Style.Triggers>
    <Trigger Property="Validation.HasError" Value="true">
      <Setter Property="ToolTip" Value="{Binding RelativeSource={RelativeSource Self},
                    Path=(Validation.Errors)[0].ErrorContent}" />
    </Trigger>
  </Style.Triggers>
</Style>

I have a lot of the stuff (MiHeight, Margin, etc.)in the style because I have a lot of these textboxes and they’re almost exactly the same. In fact, there’s a lot more in common than just the style. The details of the binding to the class MySettings are almost the same. The only difference is which particular property the textbox is binding too. Additionally, I always user TextBox_Error for Validation.Error.

Is there a way to put the binding info in Style or Data Template so I don’t have to keep typing it for each textbox?

I would need to be able to assign an individual property (Path) for each textbox, and I suppose I still need the ability to not use any of it for some particular textbox added in the future (that has nothing to do with databinding to MySettings).

Is there a way to put the TextBox_Error part inside of style or DataTemplate? Using Setter Property did not seem to work for me.

I keep mentioning Data Template as I think the answer might have something to do with that based on reading Pro Silverlight 2 in C# 2008. However, I wasn’t able to figure it out. I also tried adding stuff to “Style” as you can see from the commented out stuff in that section.

Thanks,

Dave

  • 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-17T18:47:21+00:00Added an answer on May 17, 2026 at 6:47 pm

    I dont think that there is a way to do what you are asking. However, I do think that you could go about it a different way.

    What I would look into, is creating a custom control that extends TextBox, then create some dependency properties that, when the control is initialised, setup the bindings and error validation.

    This way you can use your custom textbox all over your app and control every property, and even style them the same (just change the target type of your style)

    HTH

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

Sidebar

Related Questions

I have a table name Discount that has the following schema: PK DiscountID int
C sharp newbie question...I have a simple asp.net form that has a textbox that
I have a TextBox that has the TextChanged event set declaratively. In some cases,
Where do i find the staticresources defined? I have a textbox that has the
Good day I have a custom TextBox that has a IndicatorTextBox.ui.xml file as well
I have a Custom Control that has multiple textbox fields and a checkbox contained
I have a ASP.NET web page that contains many textboxes. Each textbox has a
I have a Window that has two primary areas. One is a TextBox inside
I have a user control that has a textbox. I have tried to expose
I have the following XAML code as part of a custom control: <telerik:RadTreeView x:Name=treeModules>

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.