Hi Anja,
your code works properly. Please, check assignment of DataContext and Immediate Window. Following demo with yours code works properly.
XAML:
<Window x:Class="WpfApp1.Window041"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfApp041"
mc:Ignorable="d"
Title="Window041" Height="450" Width="800">
<Window.DataContext>
<local:ViewModel/>
</Window.DataContext>
<StackPanel>
<Button Content="Click to check" Command="{Binding}"/>
<TextBlock x:Name="TblMessage" Text="{Binding MessageError}"/>
</StackPanel>
</Window>
And ViewModel:
using System;
using System.ComponentModel;
using System.Windows;
using System.Windows.Input;
namespace WpfApp041
{
public class ViewModel : ICommand, INotifyPropertyChanged
{
private string _messageError;
public string MessageError
{
get => _messageError;
set
{
_messageError = value;
OnPropertyChanged("MessageError");
}
}
public void SaveChangesNew()
{
//string name = CategoryName;
//bool global = CategoryIsGlobal;
//bool obsolete = CategoryIsObsolete;
//int projectId = ProjectId;
MessageError = "Den er ikke gemt";
}
public void Execute(object parameter) => SaveChangesNew();
public event EventHandler CanExecuteChanged;
public bool CanExecute(object parameter) => true;
#region INotifyPropertyChanged Members
public event PropertyChangedEventHandler PropertyChanged;
public void OnPropertyChanged(string propertyName) =>
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
#endregion
}
}