У меня есть пользовательский элемент управления с сеткой данных WPF. Я использовал этот пользовательский элемент управления в форме Windows, используя Element Host.
Я могу привязать данные к пользовательскому элементу управления с помощью ListCollectionView, но когда я делаю обновления в сетке данных, изменения не отражаются обратно.
Я установил режим = двухсторонний, но безрезультатно.
Есть идеи?
Вот пример моего кода:
UserControl.xaml
<my:DataGrid ItemsSource="{Binding}"
HorizontalScrollBarVisibility="Hidden" SelectionMode="Extended"
CanUserAddRows="False" CanUserDeleteRows="False"
CanUserResizeRows="False" CanUserSortColumns="False"
AutoGenerateColumns="False"
RowHeaderWidth="20" RowHeight="25" Width="Auto" Height="Auto"
RowStyle="{StaticResource RowSelected1}"
CellStyle="{StaticResource RowSelected}"
GridLinesVisibility="Horizontal" >
<my:DataGrid.GroupStyle>
<GroupStyle ContainerStyle="{StaticResource GroupHeaderStyle1}">
<GroupStyle.Panel>
<ItemsPanelTemplate>
<my:DataGridRowsPresenter/>
</ItemsPanelTemplate>
</GroupStyle.Panel>
</GroupStyle>
</my:DataGrid.GroupStyle>
<my:DataGrid.Columns>
<Controls:LabelTextBoxColumn Header="Tread BarCode" Width="2*"
HorizontalAlignment="Left" VerticalAlignment="Center"
ElementStyle="{StaticResource BaseLabelCellStyle}"
EditingElementStyle="{StaticResource BaseTextBoxCellStyle}"
Binding="{Binding Name,Mode=TwoWay}"/>
Код в моей форме Windows frm1:
this.sdaTrueName.Fill(this.dstrueSrch1.dtTrue);
view = new ListCollectionView(this.dstrueSrch1.dtTrue.ToList());
view.GroupDescriptions.Add(new PropertyGroupDescription("Name"));
UserControlABC.DataContext = view;
Мне нужно сохранить данные обратно в базу данных. Я использую набор данных и таблицы данных.
Пожалуйста, помогите мне с любыми идеями?
Я попытался отладить свою программу, и в окне вывода я получил ошибку.
System.Windows.Data Warning: 52 : Created BindingExpression (hash=19378226) for Binding (hash=19699911)
System.Windows.Data Warning: 54 : Path: 'IsEnabled'
System.Windows.Data Warning: 56 : BindingExpression (hash=19378226): Default mode resolved to OneWay
System.Windows.Data Warning: 57 : BindingExpression (hash=19378226): Default update trigger resolved to PropertyChanged
System.Windows.Data Warning: 58 : BindingExpression (hash=19378226): Attach to System.Windows.Controls.TextBox.IsEnabled (hash=56309765)
System.Windows.Data Warning: 63 : BindingExpression (hash=19378226): Resolving source
System.Windows.Data Warning: 66 : BindingExpression (hash=19378226): Found data context element: TextBox (hash=56309765) (OK)
System.Windows.Data Warning: 67 : BindingExpression (hash=19378226): DataContext is null
System.Windows.Data Warning: 61 : BindingExpression (hash=19378226): Resolve source deferred
System.Windows.Data Warning: 63 : BindingExpression (hash=19378226): Resolving source
System.Windows.Data Warning: 66 : BindingExpression (hash=19378226): Found data context element: TextBox (hash=56309765) (OK)
System.Windows.Data Warning: 74 : BindingExpression (hash=19378226): Activate with root item dataTableExtrRow (hash=24854661)
System.Windows.Data Warning: 104 : BindingExpression (hash=19378226): At level 0 - for dataTableExtrRow.IsEnabled found accessor <null>
System.Windows.Data Error: 39 : BindingExpression path error: 'IsEnabled' property not found on 'object' ''dataTableExtrRow' (HashCode=24854661)'.
BindingExpression:Path=IsEnabled; DataItem='dtextruderWindupRow' (HashCode=24854661); target element is 'TextBox' (Name=''); target property is 'IsEnabled' (type 'Boolean')
System.Windows.Data Warning: 76 : BindingExpression (hash=19378226): TransferValue - got raw value {DependencyProperty.UnsetValue}
System.Windows.Data Warning: 84 : BindingExpression (hash=19378226): TransferValue - using fallback/default value 'True'
System.Windows.Data Warning: 85 : BindingExpression (hash=19378226): TransferValue - using final value 'True'"
Вот код XAML в моем окне ресурсов в моем пользовательском элементе управления:
<Style x:Key="BaseTextBoxCellStyle" TargetType="{x:Type TextBox}">
<Setter Property="IsEnabled" Value="{Binding
IsEnabled,diag:PresentationTraceSources.TraceLevel=High}"/>
</Style>
<Style x:Key="BaseLabelCellStyle" TargetType="{x:Type Label}">
<Setter Property="IsEnabled" Value="{Binding IsEnabled}"/>
<Setter Property="Margin" Value="0,-3,0,0"/>
</Style>
Вот мой код в моей таблице данных WPF:
<Controls:LabelTextBoxColumn
Header="Tread BarCode" Width="2*"
HorizontalAlignment="Left" VerticalAlignment="Center"
ElementStyle="{StaticResource BaseLabelCellStyle}"
EditingElementStyle="{StaticResource BaseTextBoxCellStyle}"
Binding="{Binding rollCallID,Mode=TwoWay}"/>
Я не могу понять эту ошибку.