Невозможно получить обработанный XPS FlowDocument для обновления связанных с данными элементов / полей
В следующем фрагменте кода FlowDocument
что связано с видом CustomFormPreviewView
имеет это TextBlock
элементы, CustomFormTextField
связано одним из двух способов:
// Binding Option 1 - FlowDocument fields populated on XPS
view.ShowDialog();
// Binding Option 2 - FlowDocument fields NOT populated on XPS
view.UpdateLayout();
Только первая опция, показывающая фактическое диалоговое окно, приводит к тому, что последующее поколение XPS содержит заполненные текстовые поля / элементы, даже если оба вызова приводят к вызову CustomFormsTemplateTable.UpdateBindingsInTableCell
(следы стека ниже).
FlowDocument
<FlowDocument xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:vm="clr-namespace:ViewModels;assembly=ViewModels" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xml:space="preserve" PageWidth="816" PageHeight="1056" PagePadding="48,48,48,48" AllowDrop="True">
...
<Paragraph>
<Run FontSize="14" xml:space="preserve" />
<vm:CustomFormsTextField SerializableFieldName="Entity.AssignedTo" SerializableDisplayName="Assigned to" SerializableStringFormat="" IsInDesignMode="{Binding Path=IsInDesignMode}" FontFamily="Arial" FontStyle="Normal" FontWeight="Normal" FontSize="14" Foreground="#FF000000" TextWrapping="Wrap">
<vm:CustomFormsTextField.TextDecorations>
<TextDecorationCollection />
</vm:CustomFormsTextField.TextDecorations>
</vm:CustomFormsTextField>
</Paragraph>
...
</FlowDocument>
CustomFormsTextField
public class CustomFormsTextField : TextBlock
{
...
}
CustomFormViewModel
public XpsDocument XpsDocument
{
get
{
return CustomFormHelper.ConvertFlowDocumentToXpsDocument(this.FlowDocument);
}
}
XPS Генерация привязанного к данным FlowDocument
var view = new CustomFormPreviewView();
view.ViewModel = new CustomFormViewModel(Entity.form_id, (int)Record);
FixedDocumentSequence sequence;
sequence = view.ViewModel.XpsDocument.GetFixedDocumentSequence();
// Binding Option 1 - FlowDocument fields populated on XPS
view.ShowDialog();
// Binding Option 2 - FlowDocument fields NOT populated on XPS
view.UpdateLayout();
using (var xpsDoc = new System.Windows.Xps.Packaging.XpsDocument(path_XPS, System.IO.FileAccess.Write, System.IO.Packaging.CompressionOption.SuperFast))
{
var writer = System.Windows.Xps.Packaging.XpsDocument.CreateXpsDocumentWriter(xpsDoc);
if (sequence != null)
{
sequence.References.Select(r => r.GetDocument(true)).ToList().ForEach(doc => doc.Pages.ToList().ForEach(page => page.UpdateLayout()));
}
writer.Write(sequence);
}
В приведенных ниже трассировках стека разделы "Связывание WPF" идентичны для обоих параметров, однако разделы "Отображение окна" различны. Как процесс рендеринга окна обновляет FlowDocument, чтобы заполненные элементы данных (CustomFormTextField) заполнялись?
Трассировка стека - вариант связывания 1
// WPF Binding ////////////////////////////////////////////////////////////////////////////////////////////////////////
ViewModels.dll!ViewModels.CustomFormsTemplateTable.UpdateBindingsInTableCell(System.Windows.Documents.TableCell cell, int row) Line 225 C# Symbols loaded.
ViewModels.dll!ViewModels.CustomFormsTemplateTable.DrawRows(System.Collections.IEnumerable rows) Line 172 C# Symbols loaded.
ViewModels.dll!ViewModels.CustomFormsTemplateTable.Draw(System.Collections.IEnumerable rows) Line 153 C# Symbols loaded.
ViewModels.dll!ViewModels.CustomFormsTemplateTable.OnSerializableItemsSourceChanged(System.Windows.DependencyObject o, System.Windows.DependencyPropertyChangedEventArgs e) Line 126 C# Symbols loaded.
WindowsBase.dll!System.Windows.DependencyObject.OnPropertyChanged(System.Windows.DependencyPropertyChangedEventArgs e) Unknown No symbols loaded.
PresentationFramework.dll!System.Windows.FrameworkContentElement.OnPropertyChanged(System.Windows.DependencyPropertyChangedEventArgs e) Unknown No symbols loaded.
PresentationFramework.dll!System.Windows.Documents.TextElement.OnPropertyChanged(System.Windows.DependencyPropertyChangedEventArgs e) Unknown No symbols loaded.
WindowsBase.dll!System.Windows.DependencyObject.NotifyPropertyChange(System.Windows.DependencyPropertyChangedEventArgs args) Unknown No symbols loaded.
WindowsBase.dll!System.Windows.DependencyObject.UpdateEffectiveValue(System.Windows.EntryIndex entryIndex, System.Windows.DependencyProperty dp, System.Windows.PropertyMetadata metadata, System.Windows.EffectiveValueEntry oldEntry, ref System.Windows.EffectiveValueEntry newEntry, bool coerceWithDeferredReference, bool coerceWithCurrentValue, System.Windows.OperationType operationType) Unknown No symbols loaded.
WindowsBase.dll!System.Windows.DependencyObject.InvalidateProperty(System.Windows.DependencyProperty dp, bool preserveCurrentValue) Unknown No symbols loaded.
PresentationFramework.dll!System.Windows.Data.BindingExpressionBase.Invalidate(bool isASubPropertyChange) Unknown No symbols loaded.
PresentationFramework.dll!System.Windows.Data.BindingExpression.TransferValue(object newValue, bool isASubPropertyChange) Unknown No symbols loaded.
PresentationFramework.dll!System.Windows.Data.BindingExpression.Activate(object item) Unknown No symbols loaded.
PresentationFramework.dll!System.Windows.Data.BindingExpression.AttachToContext(System.Windows.Data.BindingExpression.AttachAttempt attempt) Unknown No symbols loaded.
PresentationFramework.dll!System.Windows.Data.BindingExpression.MS.Internal.Data.IDataBindEngineClient.AttachToContext(bool lastChance) Unknown No symbols loaded.
PresentationFramework.dll!MS.Internal.Data.DataBindEngine.Task.Run(bool lastChance) Unknown No symbols loaded.
PresentationFramework.dll!MS.Internal.Data.DataBindEngine.Run(object arg) Unknown No symbols loaded.
// Window Rendering ///////////////////////////////////////////////////////////////////////////////////////////////////
PresentationCore.dll!System.Windows.ContextLayoutManager.fireLayoutUpdateEvent() Unknown No symbols loaded.
PresentationCore.dll!System.Windows.ContextLayoutManager.UpdateLayout() Unknown No symbols loaded.
PresentationCore.dll!System.Windows.Interop.HwndSource.SetLayoutSize() Unknown No symbols loaded.
PresentationCore.dll!System.Windows.Interop.HwndSource.RootVisualInternal.set(System.Windows.Media.Visual value) Unknown No symbols loaded.
PresentationFramework.dll!System.Windows.Window.SetRootVisual() Unknown No symbols loaded.
PresentationFramework.dll!System.Windows.Window.SetRootVisualAndUpdateSTC() Unknown No symbols loaded.
PresentationFramework.dll!System.Windows.Window.SetupInitialState(double requestedTop, double requestedLeft, double requestedWidth, double requestedHeight) Unknown No symbols loaded.
PresentationFramework.dll!System.Windows.Window.CreateSourceWindow(bool duringShow) Unknown No symbols loaded.
PresentationFramework.dll!System.Windows.Window.ShowHelper(object booleanBox) Unknown No symbols loaded.
PresentationFramework.dll!System.Windows.Window.ShowDialog() Unknown No symbols loaded.
Трассировка стека - вариант связывания 2
// WPF Binding ////////////////////////////////////////////////////////////////////////////////////////////////////////
ViewModels.dll!ViewModels.CustomFormsTemplateTable.UpdateBindingsInTableCell(System.Windows.Documents.TableCell cell, int row) Line 236 C# Symbols loaded.
ViewModels.dll!ViewModels.CustomFormsTemplateTable.DrawRows(System.Collections.IEnumerable rows) Line 172 C# Symbols loaded.
ViewModels.dll!ViewModels.CustomFormsTemplateTable.Draw(System.Collections.IEnumerable rows) Line 153 C# Symbols loaded.
ViewModels.dll!ViewModels.CustomFormsTemplateTable.OnSerializableItemsSourceChanged(System.Windows.DependencyObject o, System.Windows.DependencyPropertyChangedEventArgs e) Line 126 C# Symbols loaded.
WindowsBase.dll!System.Windows.DependencyObject.OnPropertyChanged(System.Windows.DependencyPropertyChangedEventArgs e) Unknown No symbols loaded.
PresentationFramework.dll!System.Windows.FrameworkContentElement.OnPropertyChanged(System.Windows.DependencyPropertyChangedEventArgs e) Unknown No symbols loaded.
PresentationFramework.dll!System.Windows.Documents.TextElement.OnPropertyChanged(System.Windows.DependencyPropertyChangedEventArgs e) Unknown No symbols loaded.
WindowsBase.dll!System.Windows.DependencyObject.NotifyPropertyChange(System.Windows.DependencyPropertyChangedEventArgs args) Unknown No symbols loaded.
WindowsBase.dll!System.Windows.DependencyObject.UpdateEffectiveValue(System.Windows.EntryIndex entryIndex, System.Windows.DependencyProperty dp, System.Windows.PropertyMetadata metadata, System.Windows.EffectiveValueEntry oldEntry, ref System.Windows.EffectiveValueEntry newEntry, bool coerceWithDeferredReference, bool coerceWithCurrentValue, System.Windows.OperationType operationType) Unknown No symbols loaded.
WindowsBase.dll!System.Windows.DependencyObject.InvalidateProperty(System.Windows.DependencyProperty dp, bool preserveCurrentValue) Unknown No symbols loaded.
PresentationFramework.dll!System.Windows.Data.BindingExpressionBase.Invalidate(bool isASubPropertyChange) Unknown No symbols loaded.
PresentationFramework.dll!System.Windows.Data.BindingExpression.TransferValue(object newValue, bool isASubPropertyChange) Unknown No symbols loaded.
PresentationFramework.dll!System.Windows.Data.BindingExpression.Activate(object item) Unknown No symbols loaded.
PresentationFramework.dll!System.Windows.Data.BindingExpression.AttachToContext(System.Windows.Data.BindingExpression.AttachAttempt attempt) Unknown No symbols loaded.
PresentationFramework.dll!System.Windows.Data.BindingExpression.MS.Internal.Data.IDataBindEngineClient.AttachToContext(bool lastChance) Unknown No symbols loaded.
PresentationFramework.dll!MS.Internal.Data.DataBindEngine.Task.Run(bool lastChance) Unknown No symbols loaded.
PresentationFramework.dll!MS.Internal.Data.DataBindEngine.Run(object arg) Unknown No symbols loaded.
// Window Rendering ///////////////////////////////////////////////////////////////////////////////////////////////////
PresentationCore.dll!System.Windows.ContextLayoutManager.fireLayoutUpdateEvent() Unknown No symbols loaded.
PresentationCore.dll!System.Windows.ContextLayoutManager.UpdateLayout() Unknown No symbols loaded.
Примечание: вызов GetFixedDocumentSequence
дополнительное время, после UpdateLayout
казалось, заставляет заполнять элементы / поля (только вызов UpdateLayout
, GetFixedDocumentSequence
тоже не работает):
sequence = view.ViewModel.XpsDocument.GetFixedDocumentSequence();
view.UpdateLayout();
sequence = view.ViewModel.XpsDocument.GetFixedDocumentSequence();
Я все еще хотел бы знать, как заставить элементы ( CustomFormsTextField
) в обновление их связанных данных (есть ли прямой, публичный метод для этого)?