MyView.xaml
<UserControl x:Class="CCTrayHelperWPF.View.StatusView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="30" d:DesignWidth="1200">
<Grid >
<Label Content="{Binding Message}">
</Label>
</Grid>
StatusViewModel .cs
public class StatusViewModel : ViewModelBase --> this class has inherited INotifyPropertyChanged
{
ObservableCollection<Status> _statusData;
public StatusViewModel()
{
this._statusData = new ObservableCollection<Status>();
}
public ObservableCollection<Status> ProjectStatus
{
get { return _statusData; }
}
}
Status.cs
public class Status : ViewModelBase
{
private string _message;
public string Message
{
get { return _message; }
set
{
if (_message == value) return;
_message = value;
OnPropertyChanged("Message");
}
}
}
In main window where I intergrated the view usercontrol giving the dataContext
MainWindow.xaml.cs
if (!DesignerProperties.GetIsInDesignMode(this))
{
StatusViewModel statusModel = new StatusViewModel(controller);
this.StatusView.DataContext = statusModel;
}
Now my question is: Why am I seein this binding error?
Error is: BindingExpression path error: 'Message' property not found on 'object' ''StatusViewModel' (HashCode=44528608)'. BindingExpression:Path=Message; DataItem='StatusViewModel' (HashCode=44528608); target element is 'Label' (Name=''); target property is 'Content' (type 'Object')
There is a lot of stuff going on here and some good responses already. As said before, the first problem is that your DataContext object type does not define a property called Message.
The second problem is that you are trying to use a single property from an ObservableCollection. How do you intend for the Label to know which item in the collection it should be binding to?
There is a third concern I have: why are you using a Label? Labels in WPF/SL are not the same as in WinForms and WebForms. They are heavyweight wrappers around a TextBlock that provide keyboard directionality to a target field (in other words, if the Label was FirstName you could use the keyboard to go to the related FirstNameTextBox). If all you want to do is present readonly text on the screen, use TextBlock instead.