Cristiano
Cristiano

Reputation: 131

Two-way binding (WPF) half in code, half in XAML

I got this XAML:

<Window.Resources>
        <local:Member x:Key="currentMember" x:Name="currentMember" SubscriptionDate="{x:Static sys:DateTime.Now}" />
    </Window.Resources>

And after, in a StackPanel:

<StackPanel DataContext="{StaticResource currentMember}">
<TextBox x:Name="Name" Text="{Binding Path=Name, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"></TextBox>
<Button Click="DoStuff">do stuff</Button>

Now, for example, i wanted to change the Name textbox when i press the button (using databinding):

private void DoStuff(object sender, RoutedEventArgs e)
{
    Member currentMember = (Member)this.Resources["currentMember"];
    currentMember.Name = "Cristiano"; //Doesn't work
}

What's wrong?

Upvotes: 0

Views: 66

Answers (1)

Gustavo Cantero
Gustavo Cantero

Reputation: 510

Does Member class implemens INotifyPropertyChanged? May be the problem is because Member class not inherit INotifyPropertyChanged.

Upvotes: 1

Related Questions