0
我有一個簡單的數據網格與2列,我使用可觀察集合填充。要求是爲其中一列啓用單元格編輯,然後使用按鈕將列數據保存在某處。這是我迄今已實現了它:WPF Datagrid單元格值編輯C#
視圖模型:
public class PlanningResult : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
private void NotifyPropertyChanged([CallerMemberName] String propertyName = "")
{
if (PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
public string ProducerName { get; set; }
public string leasename { get; set; }
}
觀察到的集合:
ObservableCollection<PlanningResult> populatePatternData = new ObservableCollection<PlanningResult>();
public ObservableCollection<PlanningResult> PopulatePatternData
{
get { return populatePatternData; }
set
{
populatePatternData = value;
base.OnPropertyChanged("StringList");
}
}
XAML:我設置了 「IsReadOnly=False
」 爲物業ProducerName
,因此允許用戶在需要時更新此值。
<DataGrid x:Name="PrintReport" ItemsSource="{Binding PopulatePatternData}" AutoGenerateColumns="False" FontFamily="Tahoma" FontSize="12" CanUserSortColumns="False"
HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch" AlternatingRowBackground="Gainsboro" AlternationCount="1"
SelectionMode="Extended" SelectionUnit="Cell" >
<DataGrid.Columns>
<DataGridTextColumn Header="Pattern" Binding="{Binding ProducerName}" IsReadOnly="False" >
<DataGridTextColumn.ElementStyle>
<Style>
<Setter Property="TextBlock.TextWrapping" Value="Wrap" />
<Setter Property="TextBlock.TextAlignment" Value="Center"/>
</Style>
</DataGridTextColumn.ElementStyle>
</DataGridTextColumn>
<DataGridTextColumn Header="Lease" Binding="{Binding leasename}" IsReadOnly="True" >
<DataGridTextColumn.ElementStyle>
<Style>
<Setter Property="TextBlock.TextWrapping" Value="Wrap" />
<Setter Property="TextBlock.TextAlignment" Value="Center"/>
</Style>
</DataGridTextColumn.ElementStyle>
</DataGridTextColumn>
我的問題是什麼是在如何「得到列(ProducerName
)的更新值」,並重新填充observable collection
方面的下一步是什麼?
哇,這很容易! – user7157732