У меня есть ObservableCollection<T>
в ViewModel
.
private ObservableCollectionX<SSYLine> _ssyLines = new ObservableCollectionX<SSYLine>();
public ObservableCollectionX<SSYLine> SsyLines
{
get { return _ssyLines; }
set
{
if (Setter(ref _ssyLines, value, nameof(SsyLines)))
{
}
}
}
Поэтому я добавляю новую строку, например this :
public void AddNewLine(SSYLine line)
{
if (IsEnabled)
{
line.PropertyChanged += LinePropertyChangedHandler;
SsyLines.Add(line);
SelectedLine = SsyLines[SsyLines.Count - 1];
}
}
PropertyChanged в классе (SSYLine):
public event PropertyChangedEventHandler PropertyChanged;
private void OnPropertyChanged(string propName)
{
if (PropertyChanged != null)
{
PropertyChanged.Invoke(this, new PropertyChangedEventArgs(propName));
}
}
Мой XAML
код:
<DataGrid ItemsSource="{Binding SsyLines, Mode=TwoWay}" x:Name="SsyDatagrid" Grid.Row="1" CanUserReorderColumns="False" CanUserSortColumns="False" CanUserAddRows="False"
SelectionChanged="LineSelectionChangedHandler"
HeadersVisibility="Column"
SelectedItem="{Binding SelectedLine, Mode=TwoWay}"
GridLinesVisibility="None" SourceUpdated="SsyDatagrid_SourceUpdated" BorderThickness="0" SelectionMode="Single" CanUserResizeColumns="False" CanUserResizeRows="False" Background="Transparent" AutoGenerateColumns="False" Margin="0,9,0,0"
CurrentCellChanged="LinesDatagrid_CurrentCellChanged">
Текстовое поле:
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBox x:Name="LineType" Width="Auto"
Text="{Binding detailType, Mode=TwoWay}"
LostFocus="TextBoxLostFocus"
GotKeyboardFocus="TextBoxGotKeyboardFocusHandler"
HorizontalContentAlignment="Right" >
<TextBox.Style>
<Style TargetType="{x:Type TextBox}" BasedOn="{StaticResource {x:Type TextBox}}">
<Style.Triggers>
<DataTrigger
Binding="{Binding ExplicitValidations,UpdateSourceTrigger=PropertyChanged,NotifyOnSourceUpdated=True}"
Value="True" >
<Setter Property="Background" Value="LightGreen"/>
</DataTrigger>
</Style.Triggers>
</Style>
</TextBox.Style>
</TextBox>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
Позже я получаю некоторые данные из database
и для каждой записи я добавляю строку в ObservableCollection
. У меня 4 записи. 4 строки создаются правильно, но ни одна из textboxes
не имеет значения. ObservableCollection
правильно, с правильными данными. Проблема сохраняется только на TextBox
значениях.
Что мне здесь не хватает?
Спасибо.