Link to home
Start Free TrialLog in
Avatar of bryan_z
bryan_zFlag for Canada

asked on

How do you databind in WPF to a local variable

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?

ASKER CERTIFIED SOLUTION
Avatar of ashraf882
ashraf882
Flag of Bangladesh image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of bryan_z

ASKER

Hi,

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:

http://www.wrox.com/WileyCDA/Section/Windows-Presentation-Foundation-WPF-Data-Binding-with-C-2005.id-305562.html

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;


<Window.Resources>
   <ObjectDataProvider  MethodName="GetTheBook"  x:Key="theBook"/>
</Window.Resources>

...
<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

Avatar of bryan_z

ASKER

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.