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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T17:04:10+00:00 2026-06-04T17:04:10+00:00

I have run into a problem in my app and I can’t get past

  • 0

I have run into a problem in my app and I can’t get past it. I have created the following simple WPF app to illustrate the situation.

MainWindow.xaml:

<Window x:Class="GlobalDataTemplate.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:my="clr-namespace:GlobalDataTemplate"
        Title="MainWindow" Height="350" Width="525">
    <Window.Resources>
        <DataTemplate DataType="{x:Type my:MyData}">
            <StackPanel Background="{Binding BgColor}">
                <TextBlock Text="{Binding Text}"/>
                <TextBlock Text="{Binding Number}"/>
            </StackPanel>
        </DataTemplate>
    </Window.Resources>
    <ItemsControl>
        <ItemsControl.ItemsPanel>
            <ItemsPanelTemplate>
                <UniformGrid Columns="3" />
            </ItemsPanelTemplate>
        </ItemsControl.ItemsPanel>
        <my:MyData x:Name="NW" Text="NW" Number="1" BgColor="#FFFF0000" />
        <my:MyData x:Name="N" Text="N"  Number="2" BgColor="#FF63FF00" />
        <my:MyData x:Name="NE" Text="NE" Number="3" BgColor="#FFFFCA00" />
        <my:MyData x:Name="W" Text="W" Number="4" BgColor="#FF0037FF" />
        <my:MyData x:Name="C" Text="C" Number="5" BgColor="#FF9E00FF" />
        <my:MyData x:Name="E" Text="E" Number="6" BgColor="#FF838383" />
        <my:MyData x:Name="SW" Text="SW" Number="7"
                   BgColor="{Binding ElementName=NW, Path=BgColor}" />
        <my:MyData x:Name="S" Text="S" Number="8"
                   BgColor="{Binding ElementName=N, Path=BgColor}" />
        <my:MyData x:Name="SE" Text="SE" Number="9"
                   BgColor="{Binding ElementName=NE, Path=BgColor}" />
    </ItemsControl>
</Window>

MyData.cs:

using System.Windows;
using System.Windows.Media;

namespace GlobalDataTemplate
{
    class MyData : DependencyObject
    {
        public string Text
        {
            get { return (string)GetValue(TextProperty); }
            set { SetValue(TextProperty, value); }
        }
        public static readonly DependencyProperty TextProperty =
            DependencyProperty.Register("Text", typeof(string), typeof(MyData), new UIPropertyMetadata(null));

        public int Number
        {
            get { return (int)GetValue(NumberProperty); }
            set { SetValue(NumberProperty, value); }
        }
        public static readonly DependencyProperty NumberProperty =
            DependencyProperty.Register("Number", typeof(int), typeof(MyData), new UIPropertyMetadata(0));

        public Brush BgColor
        {
            get { return (Brush)GetValue(BgColorProperty); }
            set { SetValue(BgColorProperty, value); }
        }
        // Using a DependencyProperty as the backing store for MyProperty.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty BgColorProperty =
            DependencyProperty.Register("BgColor", typeof(Brush), typeof(MyData), new UIPropertyMetadata(null));
    }
}

From the XAML, you would expect to see a 3×3 grid with the same colors across the bottom as shows across the top. But none of the colors for the bottom row show at all (you see the white background of the window). How can I get the colors at the bottom to bind to the colors at the top properly?

I’ve also tried adding a property changed handler and setting a break point. The break point is never hit.

Thanks in advance.

  • 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-04T17:04:12+00:00Added an answer on June 4, 2026 at 5:04 pm

    When I run your code, I get this error message in the debug output:

    System.Windows.Data Error: 2 : Cannot find governing FrameworkElement or FrameworkContentElement for target element. BindingExpression:Path=BgColor; DataItem=null; target element is ‘MyData’ (HashCode=65325907); target property is ‘BgColor’ (type ‘Brush’)

    I.e. that means that WPF does not consider the MyData items as part of the logical tree.
    Therefore, derive MyData from Freezable, e.g.

    class MyData : Freezable 
    {
        protected override Freezable CreateInstanceCore()
        {
            throw new System.NotImplementedException();
        }
    
        ... put the dependency properties here ...
    
    }
    

    The “Cannot find governing FrameworkElement…” problem has to do with “inheritance contexts”; please find details here: http://blogs.msdn.com/b/nickkramer/archive/2006/08/18/705116.aspx .

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

Sidebar

Related Questions

I have run into a problem w/ my model for databinding in WPF. I
I've just installed VS2008 and have run into a problem that I'm sure can
I'm using Thauber's lovely Django schedule app , but have run into a problem:
I routinely run into this problem, and I'm not sure how to get past
I've been trying to get an app hosted on EngineYard, and have run into
I am writing an app and I have run into a problem. The first
I have run into a rather odd problem, my app crashes if I try
I have run into a problem trying to modify a form I myself have
I have run into a problem... I'm trying to use QTKit in an application
I have run into this problem a few times and I'm not happy with

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.