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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T20:47:11+00:00 2026-06-14T20:47:11+00:00

I have following code: <ControlTemplate x:Key=ViewItemTemplate TargetType=ListViewItem> <StackPanel Orientation=Horizontal> <CheckBox Margin=0,0,3,0 x:Name=CkBox> <CkBox.IsChecked> <Binding

  • 0

I have following code:

<ControlTemplate x:Key="ViewItemTemplate"
                             TargetType="ListViewItem">
                    <StackPanel Orientation="Horizontal">
                        <CheckBox Margin="0,0,3,0" x:Name="CkBox">
                            <CkBox.IsChecked>
                                <Binding Path="IsSelected"
                                     Mode="TwoWay">
                                    <Binding.RelativeSource>
                                        <RelativeSource Mode="TemplatedParent" />
                                    </Binding.RelativeSource>
                                </Binding>
                            </CkBox.IsChecked>
                            <DataTrigger Binding="{Binding InvalidForeground}" Value="true">
                                <Setter TargetName="CkBoxVisual" Property="Foreground" Value="#999999"/>
                            </DataTrigger>
                        </CheckBox>
                        <ContentPresenter />
                    </StackPanel>
            </ControlTemplate>

How can i bind InvalidForeground? I looked online for many example they tell to use DataTemplate. But when i add DataTemplate above StackPanel i get errors? Am i doing something wrong?

I am trying to bind InvalidForeground so i can add some code to it. I am getting an error: Cannot resolve symbol ‘InvalidForeground’ due to unknown DataContext.

  • 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-14T20:47:13+00:00Added an answer on June 14, 2026 at 8:47 pm
    <ControlTemplate x:Key="ViewItemTemplate"
                             TargetType="ListViewItem">
            <StackPanel Orientation="Horizontal">
                <CheckBox Margin="0,0,3,0" x:Name="CkBox">
                    <CkBox.IsChecked>
                        <Binding Path="IsSelected"
                                     Mode="TwoWay">
                            <Binding.RelativeSource>
                                <RelativeSource Mode="TemplatedParent" />
                            </Binding.RelativeSource>
                        </Binding>
                    </CkBox.IsChecked>
                     <DataTrigger Binding="{Binding InvalidForeground, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Window}}}" Value="true">
                        <Setter TargetName="CkBoxVisual" Property="Foreground" Value="#999999"/>
                    </DataTrigger>
                </CheckBox>
                <ContentPresenter />
            </StackPanel>
        </ControlTemplate>
    
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            DataContext = this;
            abc A = new abc();
            A.InvalidForeground = true;
        }
    }
    public class abc : INotifyPropertyChanged
    {
        private bool invalidForeGround;
         public bool InvalidForeground
        {
            get
            { return invalidForeGround; }
            set
            { 
                invalidForeGround = value;
                Notify("InvalidForeground");
            }
         }
         private void Notify(string propName)
         {
             if (PropertyChanged != null)
                 PropertyChanged(this, new PropertyChangedEventArgs(propName));
         }
    
        public event PropertyChangedEventHandler PropertyChanged;
    }
    

    InvalidForeground must be the property in the DataContext of the Control whose template the above code is.I hope this will help

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

Sidebar

Related Questions

I am using the following code: <ListBox x:Name=lbItems Grid.Row=1 Margin=2> <ListBox.Template> <ControlTemplate> <Border Background={StaticResource
I have the following code: <Style x:Key=GoButton TargetType=Button> <Setter Property=Background Value=#FF2B832C/> <Setter Property=Foreground Value=#FFfdf7bd/>
I have following code in html: <div> <div style=float:left;margin:0.5em> <span class=title>Label1</span><br/> <input type=text name=name1
I have following code in a html form <select name=category class=input onchange=ShowTB(this,'suggest');> <option value=0
I have the following xaml code defined for DataGridTextColumn of a DataGrid. <DataGridTextColumn x:Name=UserIdColumn
I have the following code (only relevant snippets) <ribbon:RibbonWindow .............> <Grid> <ribbon:Ribbon> <ribbon:RibbonToggleButton x:Name=Button2
I have following code in initialization im = imread('Image02.tif'); figure(); imagesc(im); colormap(gray); [hImage hfig
I have following code <div id=main> <div id=one> </div> <div id=two> </div> <div id=three>
I have following code for updating user's column public void UpdateLastModifiedDate(string username) { using
I have following code for loading image from url in xml parsing endElement method

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.