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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T05:47:54+00:00 2026-05-12T05:47:54+00:00

I am trying to bind a property (Button.Background) to a property on my custom

  • 0

I am trying to bind a property (Button.Background) to a property on my custom attached property.

In a C# file I have

public static class Square
{
    public static readonly DependencyProperty PlayerProperty =
        DependencyProperty.RegisterAttached
        (
            name           : "Player",
            propertyType   : typeof(Player),
            ownerType      : typeof(UIElement),
            defaultMetadata: new FrameworkPropertyMetadata(null)
        );

    public static Player GetPlayer(UIElement element)
    {
        return (Player)element.GetValue(PlayerProperty);
    }

    public static void SetPlayer(UIElement element, Player player)
    {
        element.SetValue(PlayerProperty, player);
    }

    // Other attached properties
}

A snippet of my XAML is

<Grid Name="board" Grid.Row="1" Grid.Column="1">
    <Grid.Resources>
        <Style TargetType="{x:Type Button}">
            <Setter Property="Height" Value="20" />
            <Setter Property="Width" Value="20" />
            <Setter Property="BorderThickness" Value="3" />
            <Setter Property="Background"
                Value="{Binding Path=(l:Square.Player).Brush, Mode=OneWay}" />
        </Style>
    </Grid.Resources>
</Grid>

This is the error I get:

Cannot convert string ‘(l:Square.Player).Brush’ in attribute ‘Path’ to object of type ‘System.Windows.PropertyPath’.

Property path is not valid. ‘Square’ does not have a public property named ‘Player’.

Error at object ‘System.Windows.Data.Binding’ in markup file ‘Gobang.Gui;component/mainwindow.xaml’ Line 148 Position 59.

But since Player is an attached property which is on Square, the above code should work, right?

  • 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-12T05:47:54+00:00Added an answer on May 12, 2026 at 5:47 am

    I believe your attached property should designate Square as the owner rather than UIElement.

    public static readonly DependencyProperty PlayerProperty =
        DependencyProperty.RegisterAttached("Player", typeof(Player),
            typeof(Square), new FrameworkPropertyMetadata(null));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a custom class Contact . I am trying to bind a List<Contact>
I'm trying to bind a list of custom objects to a WPF Image like
I'm writing a WinForms app, and am trying to bind a boolean property on
I'm trying to bind element's Height value to Checkbox.IsChecked property. Why that's not working?
EDIT: Problem was fixed in .NET 4.0. I have been trying to bind a
I'm trying to bind a property in my DataContext to a property in a
I'm trying to bind the following shortcut: Ctrl + W to close tabs How
I'm trying to bind controls in a WPF form to an interface and I
I am trying to bind an event to a method of a particular instance
I'm trying to bind an ASP.net DropDownList to the results of an entity framework

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.