メイン ビューに DataGrid を追加しましたが、値を編集したり、新しい行を追加したりできないという問題が発生しています。行の削除は機能しますが、ここで何が間違っているのか教えてもらえますか?
編集: このプロジェクトは、MVVM Light Toolkit を使用して作成されています
MainWindow.xaml
<Window x:Class="PartExplorer.MainWindow"
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:ignore="http://www.ignore.com"
mc:Ignorable="d ignore"
Height="300"
Width="300"
Title="{Binding WelcomeTitle}"
DataContext="{Binding Main, Source={StaticResource Locator}}">
<Window.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Skins/MainSkin.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Window.Resources>
<Grid x:Name="LayoutRoot">
<DataGrid ItemsSource="{Binding PriceItems, Mode=TwoWay}" IsReadOnly="False" CanUserAddRows="True" />
</Grid>
</Window>
MainViewModel.cs
...
/// <summary>
/// The <see cref="PriceItems" /> property's name.
/// </summary>
public const string PriceItemsPropertyName = "PriceItems";
private ObservableCollection<PriceItem> _priceItems = new ObservableCollection<PriceItem>();
/// <summary>
/// Sets and gets the PriceBook property.
/// Changes to that property's value raise the PropertyChanged event.
/// </summary>
public ObservableCollection<PriceItem> PriceItems
{
get
{
return _priceItems;
}
set
{
if (_priceItems == value)
{
return;
}
RaisePropertyChanging(PriceItemsPropertyName);
_priceItems = value;
RaisePropertyChanged(PriceItemsPropertyName);
}
}
...
PriceItem.cs
public class PriceItem
{
public PriceItem()
{
Name = "";
Price = 0;
Weight = 0;
PartType = Type.Standard;
}
public PriceItem(string name, double price, int weight, Type partType)
{
Name = name;
Price = price;
Weight = weight;
PartType = partType;
}
public Type PartType { get; private set; }
public string Name { get; private set; }
public double Price { get; private set; }
public int Weight { get; private set; }
}
public enum Type
{
Standard,
Special
}