모든, 나는런타임에 데이터 그리드에 데이터를 바인딩하는 방법을
private ObservableCollection<TestClass> _testData = new ObservableCollection<TestClass>();
public ObservableCollection<TestClass> TestData
{
get { return _testData; }
set { _testData = value; }
}
로 정의 된 테스트 데이터와 함께 작동하고
<DataGrid x:Name="dataGrid" ItemsSource="{Binding TestData}".../>
을 통해 디자인 타임에 바인딩되는 몇 가지 테스트 코드를 나는
로dataGrid.ItemsSource = BuildDataGridColumns(cultureDict).Tables[0].AsDataView();
를 통해 실행 시간에 채워 가져옵니다 DataGrid
을 만들었습니다
private DataSet BuildDataGridColumns(Dictionary<string, string> cultureDict,
DataTable additionalDt = null)
{
// ...
}
그러나 위의 코드는 테스트 데이터 작업에 사용 된 그리드 비주얼을 더 이상 업데이트하지 않기 때문에 더 이상 ItemsSource="{Binding TestData}"
이 존재하지 않으므로 발생하지 않습니다. DataGrid
의 세포에 TextBox
에와 있다는 삽입 된 텍스트를 결합하기로되어 XAML은 다음과 같습니다
<DataGrid x:Name="dataGrid"
local:DataGridTextSearch.SearchValue="{Binding ElementName=searchBox, Path=Text, UpdateSourceTrigger=PropertyChanged}"
AlternatingRowBackground="Gainsboro" AlternationCount="2" HorizontalAlignment="Stretch"
VerticalAlignment="Stretch">
<DataGrid.Resources>
<local:SearchValueConverter x:Key="searchValueConverter" />
<Style TargetType="{x:Type DataGridCell}">
<Setter Property="local:DataGridTextSearch.IsTextMatch">
<Setter.Value>
<MultiBinding Converter="{StaticResource searchValueConverter}">
<Binding RelativeSource="{RelativeSource Self}" Path="Content.Text" />
<Binding RelativeSource="{RelativeSource Self}" Path="(local:DataGridTextSearch.SearchValue)" />
</MultiBinding>
</Setter.Value>
</Setter>
<Style.Triggers>
<Trigger Property="local:DataGridTextSearch.IsTextMatch" Value="True">
<Setter Property="Background" Value="Orange" />
</Trigger>
</Style.Triggers>
</Style>
</DataGrid.Resources>
<DataGrid.CellStyle>
<Style TargetType="DataGridCell" >
<Style.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter Property="Background" Value="#FF007ACC"/>
<Setter Property="Foreground" Value="White"/>
</Trigger>
</Style.Triggers>
</Style>
</DataGrid.CellStyle>
</DataGrid>
내 질문은,
DataGrid
과 동일한 바인딩을 런타임에 만드는 데이터 세트에 어떻게 만들 수 있습니까?
누군가가 이유는 내 데이터가 INotifyCollectionChanged
인터페이스를 구현하지 않는 것을 건의했다, 그러나, 데이터의 변수 특성으로, 나는 런타임에 DataGrid
에 데이터를로드 할 수 있습니다.
어떻게 데이터의 구조를 변경할 수있는 경우
INotifyPropertyChanged
를 구현하는 클래스로DataGrid
이 데이터를 바인딩 할 수 있습니다?
감사합니다.
이것은 좋은 대답이며 내가 깨닫고 어젯밤 일을 시작한 것입니다. 시간 내 주셔서 대단히 감사합니다 ... – MoonKnight