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

  • Home
  • SEARCH
  • 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 9193899
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T21:16:30+00:00 2026-06-17T21:16:30+00:00

I have two custom UserControl in my project code: TableControl and DeckControl. In the

  • 0

I have two custom UserControl in my project code: TableControl and DeckControl. In the code of the latter I would be able to access the former when it’s needed. So in my DeckControl I implemented the following property:

private TableControl m_Table;

public TableControl Table
{
    get { return m_Table; }
    set { m_Table = value; }
}

The problem is that I’m not able to set the property from XAML code:

<Canvas Core:Name="Layout" Loaded="OnLayoutLoaded">
    <Namespace:TableControl Core:Name="Table" Canvas.Left="0" Canvas.Top="0" Height="{Binding ElementName=Layout, Path=ActualHeight}" Width="{Binding ElementName=Layout, Path=ActualWidth}"/>
    <Namespace:DeckControl Core:Name="Deck" Canvas.Left="50">
</Canvas>

I tried using Reference but compiler says that the method or opera

<Namespace:DeckControl Core:Name="Deck" Canvas.Left="50" Table="{Core:Reference Name=Table}">

I tried this but it isn’t working either:

<Namespace:DeckControl Core:Name="Deck" Canvas.Left="50" Table="{Core:Static Table}">

I also tried using Binding:

<Namespace:DeckControl Core:Name="Deck" Canvas.Left="50" Table="{Binding ElementName=Table}">

Ok so… it’s my first approach to XAML and I’m still working on it… but I really can’t get it!

  • 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-17T21:16:31+00:00Added an answer on June 17, 2026 at 9:16 pm

    If you want to bind to a property in youe Model(window/Usercontrol) codebehind you have to set the DataContext in your Xaml.
    There are may ways to do this but the simpliest is just naming your window or usercontrol and binding using ElementName.

    Example for a Window:

    <Window x:Class="WpfApplication8.MainWindow"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            Title="MainWindow" Height="233" Width="143" Name="UI">
    
        <Canvas DataContext="{Binding ElementName=UI}" > <!-- Set dataContext to Window -->
            <Namespace:DeckControl Canvas.Left="50" Table="{Binding ElementName=Table}">
        </Canvas>
    </Window>
    

    And if you want the Xaml to update when Table changes your code behind should implement INotifyPropertyChanged, this will inform the Xaml that the property has changed.

    public partial class MainWindow : Window, INotifyPropertyChanged
    {
        public MainWindow()
        {
            InitializeComponent();
        }
    
        private TableControl m_Table;
    
        public TableControl Table
        {
           get { return m_Table; }
           set { m_Table = value; NotifyPropertyChanged("Table"); }
        }
    
        public event PropertyChangedEventHandler PropertyChanged;
        private void NotifyPropertyChanged(string property)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(property));
            }
        }
    }
    

    If your Table property is not a DependancyProperty you will have to chage this so you can bind.

    Example:

    public class DeckControl : UserControl
     {
         .......
    
    
    
         // Using a DependencyProperty as the backing store for Table.  This enables animation, styling, binding, etc...
         public static readonly DependencyProperty TableProperty =
             DependencyProperty.Register("Table", typeof(TableControl), typeof(DeckControl), new UIPropertyMetadata(null));
    
         public TableControl Table
         {
             get { return (TableControl)GetValue(TableProperty); }
             set { SetValue(TableProperty, value); }
         }
     }
    

    Also any property that is being binded outside the scope of the UserControl has to be a DependancyProperty.

    Example:

    public partial class DeckControl : UserControl
    {
        public DeckControl()
        {
            InitializeComponent();
        }
    
        private int myVar;
        public int MyProperty
        {
            get { return myVar; }
            set { myVar = value; }
        }
    }
    

    This will bind inside the usercontrol when it is a simple property as it is inscope.

    <UserControl .....
                 d:DesignHeight="300" d:DesignWidth="300" Name="UI">
    
        <TextBlock Text="{Binding MyProperty}" />
    </UserControl>
    

    This will not bind as its out of scope of the UserControl, MyProperty will have to be a DependancyProperty to bind here

    <Window ....
            Title="MainWindow" Height="233" Width="143" Name="UI">
    
        <Grid>
            <local:DeckControl MyProperty="{Binding Width}"  /> // Will not bind
        </Grid>
    
    </Window>
    

    Hope that makes sense 🙂

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

Sidebar

Related Questions

I have two files in my VS project: Custom.xaml and Custom.cs In my XAML
I have two custom widgets Foo extends Composite and Bar . I would like
I have a form and two custom UserControl that I made myself. one control
I do have two problems regarding custom controls: I created a custom UserControl public
I have two custom ActionFilters on an action. In first of the actionfilters, I
I have two custom value transformers contained within my Other Sources folder, bound to
I have created two custom controls. On the basis of features any one of
I have two apps that use custom URL schemes to switch between each other.
I have two helper methods inside a custom View which are called by their
I have a UITableView with two custom cells and each of them has a

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.