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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T20:33:55+00:00 2026-05-25T20:33:55+00:00

I am sure this has been asked before, but I haven’t had an easy

  • 0

I am sure this has been asked before, but I haven’t had an easy time figuring out how to phrase the query.

I have this style;

<SolidColorBrush x:Key="SemiTransparentRedBrushKey">#F0FF0000</SolidColorBrush>
<Style x:Key="TextBoxEmptyError" TargetType="{x:Type TextBox}">
    <Style.Triggers>
        <DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=Text.Length}" Value="0">
            <Setter Property="BorderBrush" Value="{StaticResource ResourceKey=SemiTransparentRedBrushKey}"/>
        </DataTrigger>
    </Style.Triggers>
</Style>

That I can apply to Textboxes to have a red border when they are empty. Its great, I can just add Style="{StaticResource TextBoxEmptyError}" to the Control Tag. But what if I want to apply this style with a trigger, so that the control only used it under certain conditions (like a binding being true)? Something like:

<TextBox.Style>
<Style TargetType="TextBox">
    <Style.Triggers>
        <DataTrigger Binding="{Binding Path=ApprovedRequired}" Value="True">
            <Setter Property="Style" Value="{StaticResource TextBoxEmptyError}"></Setter>
        </DataTrigger>
    </Style.Triggers>
</Style>

This code throws an exception though {"Style object is not allowed to affect the Style property of the object to which it applies."}

Can something like this be done?

Edit: If this cannot be done with a Style trigger because it would overwrite itself, is there another way to Conditionally apply a resource style?

Edit: I can change the question title if there is a more proper term for this action.

  • 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-25T20:33:56+00:00Added an answer on May 25, 2026 at 8:33 pm

    Styles cannot be set from a Setter within the Style, because then essentially the first Style would never exist at all.

    Since you’re looking for a Validation style, I would recommend looking into Validation.ErrorTemplate, although if that doesn’t work you can change your trigger so it modifies specific properties such as BorderBrush instead of the Style property

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

Sidebar

Related Questions

I'm not sure if this question has been asked before but are there any
I'm sure this has been asked before, but I can't seem to find it
Forgive me if this has been asked before, I am sure it has but
I'm sure this has been asked a number of time but I'm having trouble
I am sure this has been asked before but my google-fu was not able
I'm sure this question has been asked and answered before, but my Google-fu is
I'm pretty sure this has been asked before but I can't seem to find
I'm not sure if this question has been asked before but what are the
I'm sure this has been asked before, but my perusal of the search hits
I'm sure this has been asked before, but I couldn't find a working solution

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.