I'm getting the errors listed below when trying to bind to an ObservableCollection. It's binding to the collection find as it's returning the right number of records but can't seem to find the property (Name) on the object that's in the collection.
Thanks for any help. Also if there's a detail in those error messages I'm missing that points to answer that'd be good to know for future. I've searched other similar posts but they seem to be more about the datacontext of the usercontrol itself.
Edit: Forgot to add I have the datacontext set from using a datatemplate in app.xaml as such
<DataTemplate DataType="{x:Type vm:StageProgressViewModel}"><v:StageProgressView /></DataTemplate>
View.xaml
<UserControl x:Class="Program1.DatabaseConverter.Views.StageProgressView"
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"
xmlns:local="clr-Program1.DatabaseConverter.Views"
mc:Ignorable="d">
<Grid>
<ListView ItemsSource="{Binding ConverterStages}">
<ListView.ItemTemplate>
<DataTemplate>
<WrapPanel>
<TextBlock Text="{Binding Name}"/>
</WrapPanel>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</Grid>
</UserControl>
ViewModel.cs
using Program1.DatabaseConverter.MessageTypes;
using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Messaging;
using System.Collections.ObjectModel;
namespace Program1.DatabaseConverter.ViewModels
{
public class StageProgressViewModel : ViewModelBase
{
public enum StageProgress
{
NotStarted,
InProgress,
Complete,
Failed
}
public class ConverterStage
{
public StageProgress Progress;
public string Name;
}
public ObservableCollection<ConverterStage> ConverterStages { get; set; }
public StageProgressViewModel()
{
ConverterStages = new ObservableCollection<ConverterStage>();
ConverterStages.Add(new ConverterStage() { Progress = StageProgress.InProgress, Name = "Access Database" });
ConverterStages.Add(new ConverterStage() { Progress = StageProgress.NotStarted, Name = "SQL Database" });
ChangeStage(ConverterStages[0]);
}
private void ChangeStage(ConverterStage stage)
{
stage.Progress = StageProgress.InProgress;
var message = new ChangeStageDisplayedMessage();
message.model = new SelectAccessDatabaseViewModel();
Messenger.Default.Send<ChangeStageDisplayedMessage>(message);
}
}
}
Errors
System.Windows.Data Error: 40 : BindingExpression path error: 'Name' property not found on 'object' ''ConverterStage' (HashCode=7686103)'. BindingExpression:Path=Name; DataItem='ConverterStage' (HashCode=7686103); target element is 'TextBlock' (Name=''); target property is 'Text' (type 'String')
System.Windows.Data Error: 40 : BindingExpression path error: 'Name' property not found on 'object' ''ConverterStage' (HashCode=16531454)'. BindingExpression:Path=Name; DataItem='ConverterStage' (HashCode=16531454); target element is 'TextBlock' (Name=''); target property is 'Text' (type 'String')