У меня есть два элемента TabItem, каждый из которых содержит DataGrid, и в обоих из них я реализую INotifiyDataErrorInfo. Обе DataGrids питаются ViewModel с базовым классом модели (POCO). В первом TabItem все работает как требуется, но во втором TabItem DataGrid принимает ввод только в проверенных полях/ячейках. другие/непроверенные поля/ячейки позволяют мне вводить данные, но когда ячейки теряют фокус, новые вводимые символы отбрасываются/отклоняются.
Что может быть причиной?
Рабочий TabItem/DataGrid:
<UserControl x:Class = "ConfigTool.Controls.RawTagTabItem"
xmlns = "http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x = "http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc = "http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d = "http://schemas.microsoft.com/expression/blend/2008"
xmlns:ct_ctrls = "clr-namespace:ConfigTool.Controls"
mc:Ignorable = "d"
d:DesignHeight = "450" d:DesignWidth = "800">
<Grid>
<ct_ctrls:CTDataGrid x:Name = "tagsGrid" ItemsSource = "{Binding}" GridLinesVisibility = "Vertical" AlternatingRowBackground = "#C3DDE5"
AutoGenerateColumns = "False" CanUserAddRows = "True" IsReadOnly = "False"
SelectionUnit = "FullRow" SelectionMode = "Extended" BorderThickness = "3" CellEditEnding = "CellEditingEnds" RowStyle = "{StaticResource RawTagDataGridRow}">
<DataGrid.Columns>
<DataGridTextColumn x:Name = "TagName" Header = "Tag" Width = "*"
Binding = "{Binding Mode=TwoWay, Path=RawTag.TagName, UpdateSourceTrigger=PropertyChanged, ValidatesOnNotifyDataErrors=True, NotifyOnValidationError=True}"
ElementStyle = "{StaticResource ResourceKey=textBlockErrStyle}" />
<DataGridTextColumn x:Name = "TagCycle" Header = "Cycle"
Binding = "{Binding Mode=TwoWay, Path=RawTag.Cycle, UpdateSourceTrigger=PropertyChanged, ValidatesOnNotifyDataErrors=True, NotifyOnValidationError=True}"
ElementStyle = "{StaticResource ResourceKey=textBlockErrStyle}">
</DataGridTextColumn>
<DataGridTextColumn x:Name = "TagSource" Header = "Source" Width = "*"
Binding = "{Binding Mode=TwoWay, Path=RawTag.Source, UpdateSourceTrigger=PropertyChanged, ValidatesOnNotifyDataErrors=True, NotifyOnValidationError=True}"
ElementStyle = "{StaticResource ResourceKey=textBlockErrStyle}"/>
<DataGridTextColumn x:Name = "Unassigned" Header = "unassigned" Width = "*"
Binding = "{Binding Mode=OneWay, Path=RawTag.Unassigned, UpdateSourceTrigger=PropertyChanged, ValidatesOnNotifyDataErrors=False}"
ElementStyle = "{StaticResource ResourceKey=textBlockUnassignedStyle}"/>
<DataGridTemplateColumn x:Name = "editTagColumn" Header = "" CanUserResize = "True" >
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<WrapPanel>
<Button x:Name = "btnTagDelete" Click = "BtnTagDelete_Click" CommandParameter = "{Binding}" Height = "15" Width = "15" Margin = "2">
<Button.Content>
<Image Source = "../Resources/delete.png"></Image>
</Button.Content>
</Button>
</WrapPanel>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</ct_ctrls:CTDataGrid>
</Grid>
Рабочий TabItem/DataGrid НЕТ:
<UserControl x:Class = "ConfigTool.Controls.RawNotificationTabItem"
xmlns = "http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x = "http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc = "http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d = "http://schemas.microsoft.com/expression/blend/2008"
xmlns:ct_ctrls = "clr-namespace:ConfigTool.Controls"
mc:Ignorable = "d"
d:DesignHeight = "450" d:DesignWidth = "800">
<Grid>
<ct_ctrls:CTDataGrid x:Name = "notificationsGrid" ItemsSource = "{Binding}" GridLinesVisibility = "Vertical" AlternatingRowBackground = "#C3DDE5"
AutoGenerateColumns = "False" CanUserAddRows = "True" IsReadOnly = "False"
SelectionUnit = "FullRow" SelectionMode = "Extended" BorderThickness = "3" CellEditEnding = "CellEditingEnds" RowStyle = "{StaticResource NotificationDataGridRow}">
<DataGrid.Resources>
<Style x:Key = "wordWrapStyleView" TargetType = "{x:Type TextBlock}">
<Setter Property = "TextWrapping" Value = "Wrap"/>
</Style>
<Style x:Key = "wordWrapStyleEdit" TargetType = "{x:Type TextBox}">
<Setter Property = "TextWrapping" Value = "Wrap"/>
</Style>
</DataGrid.Resources>
<DataGrid.Columns>
<DataGridTemplateColumn Header = "Tag">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Grid>
<ct_ctrls:TextWithSuggestionControl x:Name = "test" DataContext = "{Binding}" ItemsSource = "{Binding Path=Tags}"
Value = "{Binding Path=Notification.TagName, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Append = "False"/>
</Grid>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTextColumn Header = "Nid" Binding = "{Binding Mode=TwoWay, Path=Notification.Nid}"/>
<DataGridCheckBoxColumn Header = "Active" Binding = "{Binding Mode=TwoWay, Path=Notification.IsActive, Converter = {StaticResource StringBoolConverter}}" IsThreeState = "False"/>
<DataGridTextColumn Header = "Type" Binding = "{Binding Mode=TwoWay, Path=Notification.Type}"/>
<DataGridTextColumn Header = "Limit" Binding = "{Binding Mode=TwoWay, Path=Notification.Limit}">
<Validation.ErrorTemplate>
<ControlTemplate>
<StackPanel>
<AdornedElementPlaceholder x:Name = "Limit"/>
<TextBlock Text = "{Binding [0].ErrorContent}" Background = "Red"/>
</StackPanel>
</ControlTemplate>
</Validation.ErrorTemplate>
</DataGridTextColumn>
<DataGridTemplateColumn Header = "Operator">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Grid>
<ComboBox x:Name = "notificationOp" DataContext = "{Binding}" ItemsSource = "{Binding Path=Operations}"
Text = "{Binding Path=Notification.Op}" IsEditable = "False" VerticalAlignment = "Top"
SelectedItem = "{Binding Path=Notification.Op, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" >
</ComboBox>
</Grid>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTextColumn Header = "Text" Binding = "{Binding Mode=TwoWay, Path=Notification.Text}"/>
<DataGridTextColumn Header = "Deadband" Binding = "{Binding Mode=TwoWay, Path=Notification.Deadband}">
<DataGridTextColumn.ElementStyle>
<Style TargetType = "TextBlock">
<Setter Property = "HorizontalAlignment" Value = "Right" />
</Style>
</DataGridTextColumn.ElementStyle>
</DataGridTextColumn>
<DataGridTextColumn Header = "Delay" ElementStyle = "{StaticResource ResourceKey=textBlockErrStyle}"
Binding = "{Binding Mode=TwoWay, Path=Notification.Delay, UpdateSourceTrigger=PropertyChanged, ValidatesOnNotifyDataErrors=True, NotifyOnValidationError=True}">
<DataGridTextColumn.CellStyle>
<Style >
<Setter Property = "FrameworkElement.HorizontalAlignment" Value = "Stretch"/>
<Setter Property = "TextBlock.TextAlignment" Value = "Right"/>
</Style>
</DataGridTextColumn.CellStyle>
</DataGridTextColumn>
<DataGridTextColumn Header = "Expand" ElementStyle = "{StaticResource ResourceKey=textBlockErrStyle}"
Binding = "{Binding Mode=TwoWay, Path=Notification.Expand, UpdateSourceTrigger=PropertyChanged, ValidatesOnNotifyDataErrors=True, NotifyOnValidationError=True}">
<DataGridTextColumn.CellStyle>
<Style >
<Setter Property = "FrameworkElement.HorizontalAlignment" Value = "Stretch"/>
<Setter Property = "TextBlock.TextAlignment" Value = "Right"/>
</Style>
</DataGridTextColumn.CellStyle>
</DataGridTextColumn>
<DataGridTextColumn Header = "SampleCount" ElementStyle = "{StaticResource ResourceKey=textBlockErrStyle}"
Binding = "{Binding Mode=TwoWay, Path=Notification.SampleCount, UpdateSourceTrigger=PropertyChanged, ValidatesOnNotifyDataErrors=True, NotifyOnValidationError=True}">
<DataGridTextColumn.CellStyle>
<Style >
<Setter Property = "FrameworkElement.HorizontalAlignment" Value = "Stretch"/>
<Setter Property = "TextBlock.TextAlignment" Value = "Right"/>
</Style>
</DataGridTextColumn.CellStyle>
</DataGridTextColumn>
<DataGridTemplateColumn Header = "DetailTemplate">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Grid>
<ct_ctrls:TextWithSuggestionControl x:Name = "test" DataContext = "{Binding}" ItemsSource = "{Binding Path=DetailTemplates}"
Value = "{Binding Path=Notification.DetailTemplate, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Append = "False"/>
</Grid>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTemplateColumn Header = "DetailParams" Width = "300" >
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Grid>
<ct_ctrls:TextWithSuggestionControl x:Name = "test" DataContext = "{Binding}" ItemsSource = "{Binding Path=Tags}"
Value = "{Binding Path=Notification.DetailParamsString, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Append = "True"/>
</Grid>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTextColumn Header = "unassigned"
Binding = "{Binding Mode=OneWay, Path=Notification.Unassigned, ValidatesOnDataErrors=False, NotifyOnValidationError=False}"
ElementStyle = "{StaticResource ResourceKey=textBlockUnassignedStyle}"/>
<DataGridTemplateColumn x:Name = "EditNotificationsColumn" Header = "">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<WrapPanel>
<Button x:Name = "btnNotificationDelete" Click = "BtnNotificationDelete_Click" Height = "15" Width = "15" Margin = "2">
<Image Source = "../Resources/delete.png"></Image>
</Button>
</WrapPanel>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</ct_ctrls:CTDataGrid>
</Grid>
DataGrid заполняются после прочтения файлов CSV ... только пытаюсь изменить (непроверенные) ячейки (которые на самом деле являются DataGridTextColumns и DataGridCheckboxColumns) вызывают проблему.
Программно или вы имеете в виду просто удалить исходный файл и создать новый файл, возможно, из-за того, что есть какие-то недопустимые/невидимые символы или что-то в этом роде?
Я удалил файл (.xaml и .xaml.cs) и воссоздал их... безуспешно. Все то же поведение.





Это довольно просто: делайте это правильно, и это сработает! ;-) Я просто забыл добавить UpdateSourceTrigger=Свойство изменено в привязку ячеек, которые отклонили ввод.
Попробуйте удалить сетку данных и добавить новую.