I 개념의 다음과 같은 증거가 있습니다이것은 WPF Datagrid 버그입니까?
이XAML 창 : 뒤에
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<DataGrid ItemsSource="{Binding Items}" AutoGenerateColumns="False" >
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding Name}" />
<DataGridTemplateColumn >
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<CheckBox IsChecked="{Binding Mode=TwoWay, Path=Enabled}" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>
</Window>
코드 :
using System.Collections.ObjectModel;
using System.Windows;
namespace WpfApplication1
{
public partial class MainWindow : Window
{
public ObservableCollection<Data> Items { get; private set; }
public MainWindow()
{
InitializeComponent();
this.Items = new ObservableCollection<Data>();
this.DataContext = this;
for (int index = 0; index < 30; index++)
{
this.Items.Add(new Data() {Enabled = true });
}
}
}
public class Data
{
public bool Enabled { get; set; }
}
}
이 응용 프로그램을 실행 상단에 약간의 상자를 선택 취소, 아래로 스크롤, 약간의 변경을 상자를 다시 열어 위로 스크롤하십시오. 확인을 다시 한 번 확인합니다.
내가 누락되었거나 Microsoft에 버그를 기입해야합니까?
EDIT : 답장을 보내 주셔서 감사합니다. INotify 또는 Checkbox와 관련이 없으며, TextBox와 동일한 작업이 수행됩니다. 스크롤 한 후 확인란을 클릭하고 일부만 선택을 취소하고 아래로 스크롤하고 위로 스크롤 한 다음 다시 확인해야 이벤트를 수행 할 필요가 없습니다.
<DataGrid ItemsSource="{Binding Items}" AutoGenerateColumns="False" >
<DataGrid.Columns>
<DataGridTemplateColumn >
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<CheckBox IsChecked="{Binding Mode=TwoWay, Path=Enabled}" />
<TextBox Text="{Binding Text}" />
</StackPanel>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>
</Window>
그리고 뒤에있는 코드 :이 VirtualRows이 어디 여부를 작업의 예상 방법이 아니기 때문에
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Windows;
namespace WpfApplication1
{
public partial class MainWindow : Window
{
public ObservableCollection<Data> Items { get; private set; }
public MainWindow()
{
InitializeComponent();
this.Items = new ObservableCollection<Data>();
this.DataContext = this;
for (int index = 0; index < 30; index++)
{
this.Items.Add(new Data() { Enabled = true, Text = index.ToString() });
}
}
}
public class Data : INotifyPropertyChanged
{
private bool _enabled;
public bool Enabled
{
get { return _enabled; }
set
{
if (value != _enabled)
{
_enabled = value;
this.OnPropertyChanged("Enabled");
}
}
}
private string _text;
public string Text
{
get { return _text; }
set
{
if (value != _text)
{
_text = value;
this.OnPropertyChanged("Text");
}
}
}
#region INotifyPropertyChanged Members
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged(string name)
{
if (this.PropertyChanged != null)
{
this.PropertyChanged(this, new PropertyChangedEventArgs(name));
}
}
#endregion
}
}
'Data'가'INotifyPropertyChanged'에서 상속 받고 속성 변경 알림을 사용하면 결과가 바뀌나요? – Rachel
재활용을 끄십시오. 세트가 호출 되나요? UpdateSourceTrigger = "PropertyChanged"가 아닌 경우 레이첼이 말한 것처럼 – Paparazzi
나는 레이첼이 제안한 것을 시도 할 것이다. – ecMode