我尝试让用户在DataGrid内部的DataGrid中更改日期。两者都是ObservableCollections。
查看:
list_ = ['Id', 'PRICE', 'LATitude', 'longitude']
required_value = list_[location]
ViewModel updateOrderCommand使用newexecuteday覆盖执行日期并将其保存在数据库中。最后,它开始:
<DataGrid VerticalContentAlignment="Center" CanUserAddRows="false" Grid.Row="0" Grid.Column="0" ItemsSource="{Binding ItemsCol, NotifyOnSourceUpdated=True, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" IsSynchronizedWithCurrentItem="True" EnableRowVirtualization="True" AutoGenerateColumns="False" Background="{DynamicResource PrimaryHueMidBrush}" SelectedItem="{Binding Items}" RenderTransformOrigin="0.5,0.5" Style="{DynamicResource MaterialDesignDataGrid}" IsReadOnly="true">
<DataGrid.Columns>
...
<DataGrid.RowDetailsTemplate>
<DataTemplate>
...
<DataGrid ScrollViewer.CanContentScroll="False" ItemsSource="{Binding PlanList, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" CanUserAddRows="False" VerticalContentAlignment="Bottom" AutoGenerateColumns="false" SelectedItem="{Binding RelativeSource={RelativeSource AncestorType={x:Type UserControl},Mode=FindAncestor}, Path=DataContext.SelectedPlan}" Background="{DynamicResource PrimaryHueDarkBrush}" Style="{DynamicResource MaterialDesignDataGrid}" IsReadOnly="false">
<DataGrid.Columns>
<DataGridTemplateColumn Header="Bearbeitungstag">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding executeDay, ValidatesOnDataErrors=True, UpdateSourceTrigger=PropertyChanged, Mode=OneWay,StringFormat={}{0:dd/MM/yyyy}}"/>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
<DataGridTemplateColumn.CellEditingTemplate>
<DataTemplate>
<DatePicker SelectedDate="{Binding RelativeSource={RelativeSource AncestorType={x:Type UserControl},Mode=FindAncestor},Path=DataContext.newexecuteDay, ValidatesOnDataErrors=True, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay,StringFormat={}{0:dd/MM/yyyy}}"/>
</DataTemplate>
</DataGridTemplateColumn.CellEditingTemplate>
</DataGridTemplateColumn>
<DataGridTemplateColumn Header="">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate >
<Button Command="{Binding RelativeSource={RelativeSource AncestorType={x:Type UserControl},Mode=FindAncestor},Path=DataContext.updateOrderCommand}" VerticalAlignment="Center" Style="{DynamicResource MaterialDesignFlatButton}">
<Viewbox Stretch="Fill">
<Canvas Width="24" Height="24">
<Path Data="M15,9H5V5H15M12,19A3,3 0 0,1 9,16A3,3 0 0,1 12,13A3,3 0 0,1 15,16A3,3 0 0,1 12,19M17,3H5C3.89,3 3,3.9 3,5V19A2,2 0 0,0 5,21H19A2,2 0 0,0 21,19V7L17,3Z" Fill="{DynamicResource SecondaryAccentBrush}" />
</Canvas>
</Viewbox>
</Button>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
...
</DataGrid.Columns>
</DataGrid>
此时,代码崩溃了
System.Windows.Markup.XamlParseException:“” DeferRefresh“ ....
在AddNew或EditItem事务中是不允许的(免费翻译未找到英语异常:-/)
我已经尝试过
CollectionViewSource.GetDefaultView(ItemsCol).Refresh();
然后不允许“刷新”。 我为第一个DataGrid尝试了一些CodeBehind CommitEdit()和CancelEdit()。
我认为我必须中止UI内的编辑模式,但是如何在MVVM环境或RowDetailsTemplate中使用
?