Welcome to the Xceed Community Sign in | Join | Help
Community Search  

Need help with Data Binding 101

Sort Posts: Previous Next
  •  05-14-2008, 6:01 PM Post no. 12283

    Need help with Data Binding 101

    I'll preface my post by saying that I'm completely new to WPF and VS 2008, although I'm an experienced VS 2003 programmer (I skipped VS 2005).

    I'm trying to get a new application going using VB 2008 and the Xceed DataGrid.  I'm starting out by simply trying to bind a table in my database to the grid and I haven't gotten very far.

    I studied the DataBinding and MasterDetail examples provided.  I also tried to use the "Creating your first DataGrid Project" section in the help files.  Since I'm getting many errors, maybe answering two basic questions first is the better approach:

    1.- Where is the App.xaml.as file in a new WPF VB app?  This file is mentioned in the help file as the place to put the code with my connection string and query.  But I can't find that file in my application or the examples provided.

    2.- The same help section mentions a XAML section that I need to bind the property I define in the App.xaml.as file.  I'm also getting errors when I try to do this, so my question is if there is a user interface provided with the grid that will build this XAML for me at design time or do I have to write XAML myself?

    Maybe after getting an answer to these first two questions I'll get over the initial hurdle, thanks in advance.

  •  05-15-2008, 8:43 AM Post no. 12299 in reply to 12283

    Re: Need help with Data Binding 101

    Application.Current (App.xaml.cs  ) is just the location I chose to place the property that exposes my data source. That said, you can have your property anywhere as long as the grid has access to it. For example, if you have a Window1 that contains  your grid, you could do an AncestorType binding to find the window and get the property (1). Another option would be in the window's constructor to set the window's DataContext to itself and access the properties directly in the binding (2).

    1- {Binding RelativeSource={RelativeSource AncestorType={x:Type local:MainWindow}}, Path=MyProperty}

    This binding assumes that you have declared an xmlns named local for your local namespace.

    2- In the ctor of the window:

    this.DataContext = this;

    {Binding Path=MyProperty}


    Technical Writer - Xceed Software

    Of all the things I've lost, I miss my mind the most. - Mark Twain
View as RSS news feed in XML
Contact | Site Map | Reviews | Legal Terms of Use | Trademarks | Privacy Statement Copyright 2008 Xceed Software Inc.