Isusse in textbox.text binfing with object property

Ajeje Brazorf 106 Reputation points
2022-09-06T09:11:44.08+00:00

Hello,
I've a classe Game with a string property Name.

 Public Class Game  
        Private _Name As String  
        Public Property Name As String  
            Get  
                Return _Name  
            End Get  
            Set(ByVal value As String)  
                _Name = value  
            End Set  
        End Property  
    End Class  

in my viewmodel I declared
Public Property Newcompetition As New Game

In the view:

<TextBox Grid.Row="3" Grid.Column="2" Grid.ColumnSpan="6" HorizontalContentAlignment="Right"  FontSize="16" FontWeight="Bold" FontFamily="Bahnschrift SemiBold" >  
            <TextBox.Text>  
                <Binding Path="Name" Source="Newcompetition"  
                   UpdateSourceTrigger="PropertyChanged" Mode="Two Way"/>  
            </TextBox.Text>  

I also placed a button, to debug purpose , with show a messagebox with newcompetition.Name value.

But binding seem not working, I still get exception that Newcompetition is empty.
Any Advice?

Windows Presentation Foundation
Windows Presentation Foundation
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
2,681 questions
VB
VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,580 questions
XAML
XAML
A language based on Extensible Markup Language (XML) that enables developers to specify a hierarchy of objects with a set of properties and logic.
767 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Ajeje Brazorf 106 Reputation points
    2022-09-08T08:02:39.037+00:00

    I finally solved:
    as Viorel-1 adive I removed the space: Mode="TwoWay", and in xaml:

    <TextBox.Text>  
                     <Binding Path="NewCompetition.Name"  
                        UpdateSourceTrigger="PropertyChanged" Mode="Two Way"/>  
                 </TextBox.Text>  
    

    I don't understand way using source and path tags it not worked, but in this way it seem to work.

    0 comments No comments