MVVM WPF Add new item to the DataGrid from Textboxes which are bound to the nested properties of the Model class

Solution 1:

I tried to replicate your problem but I had to remove the styles since you did not provide them. It works at my side, so perhaps the problem lies within the style?

enter image description here

Please delete your styles for the textboxes (ParameterTextbox) and see if it works then. If you can provide me with the source code for the style, I can take a look at it. Maybe you are overriding the text property.

edit after it turned out the style was the issue

here is an example of the style you want to accomplish in a minimalistic way.

<UserControl.Resources>
    <ControlTemplate x:Key="RoundedTextBoxCt">
        <Border 
            Width="{TemplateBinding Width}"                    
            Height="{TemplateBinding Height}"                                    
            BorderBrush="{TemplateBinding BorderBrush}"              
            BorderThickness="{TemplateBinding BorderThickness}"          
            Background="{TemplateBinding Background}"          
            x:Name="Bd" 
            CornerRadius="5">
            <ScrollViewer
                Padding="{TemplateBinding Padding}"                        
                VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}" 
                Foreground="{TemplateBinding Foreground}"
                x:Name="PART_ContentHost"/>
        </Border>
    </ControlTemplate>
    
    <Style x:Key="ParameterTextBox" TargetType="TextBox">
        <Setter Property="Width"                    Value="180"/>
        <Setter Property="Height"                   Value="35"/>
        <Setter Property="VerticalContentAlignment" Value="Center"/>
        <Setter Property="Padding"                  Value="5"/>
        <Setter Property="Foreground"               Value="Black"/>
        <Setter Property="BorderBrush"              Value="#EAEAEA"/>
        <Setter Property="BorderThickness"          Value="3"/>
        <Setter Property="Background"               Value="White"/>
        <Setter Property="Template" Value="{StaticResource RoundedTextBoxCt}"/>
    </Style>
    
    ...
    
</UserControl.Resources>

I made the control template as a separate resource, this way 'rounded textbox' can be put inside of some 'shared' assembly, and you will be able to use it for other projects as well.

It is minimalistic, as in the minimal you'll need. If you want a full-fledged text box, copy the style from here and modify it: https://docs.microsoft.com/en-us/dotnet/desktop/wpf/controls/textbox-styles-and-templates?view=netframeworkdesktop-4.8 it might look scary, but most of the time it comes down to modifying only a few rules. Once you get the hang of it, it's quite easy.

Instead of working with the setters, and even a separate control template resource, you could hard-code everything within the control template, WITHIN the setter of the control template of the textbox style, but that's up to you.

Good luck!

enter image description here