views:

44

answers:

1

Hi

When I run following code textblock is not changing.

My guess is databinding is missing either in code or XMAL.

XAML

    <Window.Resources>
        <ObjectDataProvider x:Key="PersonObj" ObjectType="{x:Type local:Person}" MethodName="GetFirstName" />
    </Window.Resources>

    <Grid>
        <!--<TextBlock  Margin="26,7,12,0" Name="myTextBlock" Text="{Binding Path=FirstName}" Height="69" VerticalAlignment="Top" />-->
        <TextBlock Margin="26,7,12,0" Name="myTextBlock" Text="{Binding FirstName, Source={StaticResource PersonObj}}" Height="69" VerticalAlignment="Top" />
    </Grid>
</Window>

CODE

namespace WpfApplication1
{

    public partial class Window1 : Window
    {
        public Window1()
        {
            InitializeComponent();
            test t = new test();
        }
        public void testing()
        {
            test t = new test();
        }    
    }

    public class Person
    {
        public String FirstName { get; set; }
        public String LastName { get; set; }

        public string GetFirstName()
        {
            return FirstName;
        }
    }
}

namespace WpfApplication1
{
    class test : Person
    {
        public test()
        {
                 this.FirstName = "John";
                 this.LastName = "S";
                 this.GetFirstName();
        }

    }
}

Thanks

+2  A: 

change the object data provider to:

<ObjectDataProvider x:Key="PersonObj" ObjectType="{x:Type local:test}" />
dnr3
So you have to use ObjectType="{x:Type local:ClassName}". myTextBlock is error message , How can I use this in mutiple class. If expcection occured in test class it will dispaly on main form, if expection occured in test1 class it will overrite it if anything there.
juniorCSharp
i'm not sure i'm following @_@. but if i get it right then i think you'll call the test1 within your test class isn't it? then you can just override the value in test class bound property
dnr3