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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T06:07:46+00:00 2026-06-04T06:07:46+00:00

I am working on a project on WPF and I have to create some

  • 0

I am working on a project on WPF and I have to create some user controls. Right now I am developing a navigation bar which allows me to navigate through a datagrid, so in my XAML file I need to pass the datagrid object to the navigation bar, but it is not working.

My navigation bar is the following:

<my:NavigationBar Data="{Binding ElementName=dataGrid1}" HorizontalAlignment="Left" Margin="6,6,0,0" Name="navigationBar1" VerticalAlignment="Top" />

And my data grid is the following:

<DataGrid AutoGenerateColumns="True" Margin="11,46,12,9" Name="dataGrid1" />

And my code behind my navigation bar is the following:

    public static readonly DependencyProperty dataProperty =
        DependencyProperty.Register("Data",
                                    typeof(DataGrid), typeof(NavigationBar));

    private DataGrid dataGrid;
    public DataGrid Data
    {
        get
        { return dataGrid; }
        set
        { dataGrid = value; }
    }

As you can see, I try to send the control to the navigation bar by doing this:

Data="{Binding ElementName=dataGrid1}"

But when I try to use the dataGrid variable in my code behind, an exception is raised because the dataGrid variable is pointing to null.

So, am I passing incorrectly the control? What am I doing wrong? Is my approach the most appropiate?

Thank you 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-04T06:07:47+00:00Added an answer on June 4, 2026 at 6:07 am

    While i agree with Andriy that there may be a better way to handle this, i do see a problem in the way you are doing Dependency Properties.

    Your backing properties for the DependencyProperty are not correct. You are not supposed to just get and set a regular value. Instead, you are supposed to use SetValue and GetValue methods.

    Should be:

    public DataGrid Data
        {
            get
            { return (DataGrid) GetValue(dataProperty); }
            set
            { SetValue(dataProperty); }
        }
    

    See: http://www.wpftutorial.net/DependencyProperties.html

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

Sidebar

Related Questions

I am working on a WPF MVVM Project. Now i have a DataGrid in
I am currently working on a C# WPF project. I have a list which
I have been working on a C# 4.0 WPF project and need to figure
I have a WPF C# project that I am working on and I have
I have blend 4 installed and whenever I create a WPF 4 project and
I am currently working on a wpf project in C#. I have a treeview
I have a WPF project in C# I am working on. I have a
I am working on a project where I have implemented MVVM for WPF desktop
I am currently working on the WPF project which involves creating a touch-screen application
I am currently working on a C# wpf project. I have a listbox and

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.