Let me preface this by saying that I am currently learning WPF and the MVVM pattern, so my question might be self answering to more experienced developers.
What I have is a simple login form with a Textbox for the name and a PasswordBox for the password. The namebox is bound to the model, while the passwordbox is sent to the command as an entire object(since you can't bind to its text property). Then a button that executes the login command. Now when the login works it is ok, but my problem is how to send return feedback of the command failing without breaking the mvvm pattern. For example changing the border color of the fields to red.
My initial instinct is to have a property of the model, which I will change on failure. However I want to learn the proper way to do it instead of hacking a solution myself (defeating the purpose of the whole thing).
Bonus questions: - Can you bind a property to a statement - for example String.isNullOrEmpty(model.name) ? - Should I entirely abandon the MVVM pattern for such a simple operation (while the rest of the project will still be using it) > - What is a good resource to learn about WPF and MVVM ?
Code of the form bellow:
<Controls:MetroWindow x:Class="Interface_WPF.View.LoginWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:Controls="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"
Title="Enter" Height="140" Width="285" WindowStartupLocation="CenterScreen" WindowStyle="None" AllowsTransparency="True" ResizeMode="NoResize">
<StackPanel>
<Grid FocusManager.FocusedElement="{Binding ElementName=NameBox}">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="200" />
</Grid.ColumnDefinitions>
<Label Grid.Row="0" Grid.Column="0" Content="Name:"/>
<Label Grid.Row="1" Grid.Column="0" Content="Password:"/>
<TextBox Grid.Column="1" Grid.Row="0" Margin="3"
Name="NameBox" Text="{Binding Login.Name, UpdateSourceTrigger=PropertyChanged}"/>
<PasswordBox Grid.Column="1" Grid.Row="1" Margin="3"
Name="PasswordBox"/>
</Grid>
<Button Command="{Binding LoginCheck}"
CommandParameter="{Binding ElementName=PasswordBox}"
Style="{DynamicResource SquareButtonStyle}" IsDefault="True" Width="100" HorizontalAlignment="Right" Margin="0,8,7.8,8" Content="Enter"/>
</StackPanel>