1

suppose i have this class:

public class Foo
{
   public Bar aBar {get; private set;}

   public Foo(String name)
   {
      aBar = new Bar()
      {
         Name = name
      }
   }
}


public class Bar
{
       public String Name {get; private set;}
}

How can i access the property Name from class Foo? this is what i have i XAML so far:

<Window.Resources>
        <ObjectDataProvider x:Key="myFoo" ObjectType="{x:Type local:Foo}">
            <ObjectDataProvider.ConstructorParameters>
                <system:String>HelloWorld</system:String>
            </ObjectDataProvider.ConstructorParameters>
        </ObjectDataProvider>
</Window.Resources>

do i have to write a method, calling with Foo.aBar.Name, .. ??

GazTheDestroyer
  • 20,722
  • 9
  • 70
  • 103
Matthias
  • 239
  • 2
  • 13

1 Answers1

1

You can use StaticResource to access the myFoo object you've created in your window resources, then it's just a case of specifying the binding path as normal:

<TextBlock Text="{Binding Source={StaticResource myFoo}, Path=aBar.Name }" />
GazTheDestroyer
  • 20,722
  • 9
  • 70
  • 103