How do you databind in WPF to a local variable

Posted on 2010-01-03
Last Modified: 2013-11-12
In my code-behind, I have a variable

public class X
    private String foo;

What is needed in the class and the XAML form to make it data bound?

What is the binding syntax for the XAML?

Question by:bryan_z
    LVL 11

    Accepted Solution

    LVL 5

    Assisted Solution


    Author Comment


    Thanks for the information but neither article provided me specifically what I was looking for. In the end I found the following article which provided the details:

    I have included a snippet of what i did to get things working.
    factory = new BookFactory();
    factory.SelectedIndex = 0;
    ObjectDataProvider provider = (ObjectDataProvider)FindResource("theBook");            
    provider.ObjectInstance = factory;
       <ObjectDataProvider  MethodName="GetTheBook"  x:Key="theBook"/>
    <TextBlock Height="23" HorizontalAlignment="Left" Margin="126,95,0,0" Name="textBlock1" 
    Text="{Binding Source={StaticResource theBook},Path=Title}" 
           VerticalAlignment="Top" Width="270" />

    Open in new window


    Author Closing Comment

    Both articles provided several good details on data bindings but where not complete and directly associated to the question. I did use them to find a 3rd article which had the specific information regarding the object data binder.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
    For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
    This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA.…
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now