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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T02:27:53+00:00 2026-06-15T02:27:53+00:00

I am new to xaml, i have following code below, my question is how

  • 0

I am new to xaml, i have following code below, my question is how can i call InvalidForeground from c# code to change the color of checkbox text?

<ControlTemplate x:Key="ItemTemplate"
                                 TargetType="ListViewItem">
                    <StackPanel Orientation="Horizontal">                    
                        <CheckBox x:Name="CkBoxVisual">
                            <CheckBox.IsChecked>
                                <Binding Path="IsSelected"
                                         Mode="TwoWay">
                                    <Binding.RelativeSource>
                                        <RelativeSource Mode="TemplatedParent" />
                                    </Binding.RelativeSource>
                                </Binding>                                
                            </CheckBox.IsChecked>
                            <DataTrigger Binding="{Binding InvalidForeground, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Window}}}" Value="true">
                                <Setter TargetName="CkBoxVisual" Property="Foreground" Value="Red"/>
                            </DataTrigger>                       
                        </CheckBox>                    
                        <ContentPresenter />                    
                    </StackPanel>
                </ControlTemplate>
  • 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-06-15T02:27:54+00:00Added an answer on June 15, 2026 at 2:27 am

    In your code, you are not calling anything. In it, you’re hoping a change of dependency property..

    But a control of type Window does not have a dependency property with the name: “InvalidForeground”.
    This trigger will never be triggered.
    What is your goal, change a property or be notified of a change (trigger)?


    Edit: There are a number of rules you must follow:

    1) The control referenced in Binding property from DataTrigger (RelativeSource):

    Binding="{Binding Path=InvalidForeground, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Window}}}"
    

    Must have a dependency property called “InvalidForeground”, which works correctly, based on this, will not work:

    {x:Type Window}
    

    its type must be declared, will work, for example:

    {x:Type my:ControlName}
    

    2) A property changed by a Trigger or DataTrigger can never be explicitly stated, for example. Will not work:

    <TextBlock Text="{Binding Any}" Foreground="#FFCCCCCC">
        <TextBlock.Style>
            <Style TargetType="TextBlock">
                <Style.Triggers>
                    <DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType=TabItem, Mode=FindAncestor}, Path=IsSelected}" Value="True">
                        <Setter Property="Foreground" Value="Black"/>
                    </DataTrigger>
                </Style.Triggers>
            </Style>
        </TextBlock.Style>
    </TextBlock>
    

    Will work:

    <TextBlock Text="{Binding Any}">
        <TextBlock.Style>
            <Style TargetType="TextBlock">
                <Setter Property="Foreground" Value="#FFCCCCCC"/>
                <Style.Triggers>
                    <DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType=TabItem, Mode=FindAncestor}, Path=IsSelected}" Value="True">
                        <Setter Property="Foreground" Value="Black"/>
                    </DataTrigger>
                </Style.Triggers>
            </Style>
        </TextBlock.Style>
    </TextBlock>
    

    3) Check the operation of Bindings using RelativeSource they have some peculiarities (you should know a little about the visual tree of WPF).

    http://msdn.microsoft.com/en-us/library/ms743599.aspx

    4) You should check that the binding is working properly and can follow these steps:
    http://www.codeproject.com/Articles/244107/Debugging-WPF-data-bindings

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

Sidebar

Related Questions

I am NEW to WPF. I have the following XAML code: </Window> ... <Canvas>
I am new to C#/XAML coding and I have the following question. I have
I have the following code in xaml: <ListView Name=listView1 IsSynchronizedWithCurrentItem=True > <ListView.View> <GridView> <GridViewColumn
In App.xaml, I have the following code: <Application.Resources> <Style x:Key=LabelTemplate TargetType={x:Type Label}> <Setter Property=Height
I have the following code in my App.xaml.cs private void App_Start(object sender, StartupEventArgs e)
In my App.xaml file, I have the following code to allow double-decker column headers
I have the following XAML code: <ListBox ItemsSource={Binding Languages}> <ListBox.ItemTemplate> <DataTemplate> <StackPanel> <Image Source={Binding
I have the following xaml code in resources: <DataTemplate DataType={x:Type s:Substance}> <StackPanel Orientation=Horizontal> <TextBlock
WP7 newb question here. I have the following code: public class KeyboardHandler : INotifyPropertyChanged
In XAML I have the following code: <Label Width=120 Height=20 Name=label1 SnapsToDevicePixels=True HorizontalAlignment=Left VerticalAlignment=Bottom>

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.