Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / wpf / src / Framework / MS / Internal / documents / DocumentPageHost.cs / 1305600 / DocumentPageHost.cs
//----------------------------------------------------------------------------
//
// Copyright (C) Microsoft Corporation. All rights reserved.
//
// File: DocumentPageHost.cs
//
// Description: Provides a view port for a page of content for a DocumentPage.
//
//---------------------------------------------------------------------------
using System;
using System.Windows; // UIElement
using System.Windows.Media; // Visual
namespace MS.Internal.Documents
{
///
/// Provides a view port for a page of content for a DocumentPage.
///
internal class DocumentPageHost : FrameworkElement
{
//-------------------------------------------------------------------
//
// Constructors
//
//-------------------------------------------------------------------
#region Constructors
///
/// Create an instance of a DocumentPageHost.
///
internal DocumentPageHost()
: base()
{
}
#endregion Constructors
//--------------------------------------------------------------------
//
// Internal Methods
//
//-------------------------------------------------------------------
#region Internal Methods
internal static void DisconnectPageVisual(Visual pageVisual)
{
// There might be a case where a visual associated with a page was
// inserted to a visual tree before. It got removed later, but GC did not
// destroy its parent yet. To workaround this case always check for the parent
// of page visual and disconnect it, when necessary.
Visual currentParent = VisualTreeHelper.GetParent(pageVisual) as Visual;
if (currentParent != null)
{
ContainerVisual pageVisualHost = currentParent as ContainerVisual;
if (pageVisualHost == null)
throw new ArgumentException(SR.Get(SRID.DocumentPageView_ParentNotDocumentPageHost), "pageVisual");
DocumentPageHost docPageHost = VisualTreeHelper.GetParent(pageVisualHost) as DocumentPageHost;
if (docPageHost == null)
throw new ArgumentException(SR.Get(SRID.DocumentPageView_ParentNotDocumentPageHost), "pageVisual");
docPageHost.PageVisual = null;
}
}
#endregion Internal Methods
//--------------------------------------------------------------------
//
// Internal Properties
//
//--------------------------------------------------------------------
#region Internal Properties
///
/// Root of visual subtree hosted by this DocumentPageHost.
///
internal Visual PageVisual
{
get
{
return _pageVisual;
}
set
{
ContainerVisual pageVisualHost;
if (_pageVisual != null)
{
pageVisualHost = VisualTreeHelper.GetParent(_pageVisual) as ContainerVisual;
Invariant.Assert(pageVisualHost != null);
pageVisualHost.Children.Clear();
this.RemoveVisualChild(pageVisualHost);
}
_pageVisual = value;
if (_pageVisual != null)
{
pageVisualHost = new ContainerVisual();
this.AddVisualChild(pageVisualHost);
pageVisualHost.Children.Add(_pageVisual);
pageVisualHost.SetValue(FlowDirectionProperty, FlowDirection.LeftToRight);
}
}
}
///
/// Internal cached offset.
///
internal Point CachedOffset;
#endregion Internal Properties
#region VisualChildren
///
/// Derived class must implement to support Visual children. The method must return
/// the child at the specified index. Index must be between 0 and GetVisualChildrenCount-1.
///
/// By default a Visual does not have any children.
///
/// Remark:
/// During this virtual call it is not valid to modify the Visual tree.
///
protected override Visual GetVisualChild(int index)
{
if (index != 0 || _pageVisual == null)
{
throw new ArgumentOutOfRangeException("index", index, SR.Get(SRID.Visual_ArgumentOutOfRange));
}
return VisualTreeHelper.GetParent(_pageVisual) as Visual;
}
///
/// Derived classes override this property to enable the Visual code to enumerate
/// the Visual children. Derived classes need to return the number of children
/// from this method.
///
/// By default a Visual does not have any children.
///
/// Remark: During this virtual method the Visual tree must not be modified.
///
protected override int VisualChildrenCount
{
get { return _pageVisual != null ? 1 : 0; }
}
#endregion VisualChildren
private Visual _pageVisual;
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
//----------------------------------------------------------------------------
//
// Copyright (C) Microsoft Corporation. All rights reserved.
//
// File: DocumentPageHost.cs
//
// Description: Provides a view port for a page of content for a DocumentPage.
//
//---------------------------------------------------------------------------
using System;
using System.Windows; // UIElement
using System.Windows.Media; // Visual
namespace MS.Internal.Documents
{
///
/// Provides a view port for a page of content for a DocumentPage.
///
internal class DocumentPageHost : FrameworkElement
{
//-------------------------------------------------------------------
//
// Constructors
//
//-------------------------------------------------------------------
#region Constructors
///
/// Create an instance of a DocumentPageHost.
///
internal DocumentPageHost()
: base()
{
}
#endregion Constructors
//--------------------------------------------------------------------
//
// Internal Methods
//
//-------------------------------------------------------------------
#region Internal Methods
internal static void DisconnectPageVisual(Visual pageVisual)
{
// There might be a case where a visual associated with a page was
// inserted to a visual tree before. It got removed later, but GC did not
// destroy its parent yet. To workaround this case always check for the parent
// of page visual and disconnect it, when necessary.
Visual currentParent = VisualTreeHelper.GetParent(pageVisual) as Visual;
if (currentParent != null)
{
ContainerVisual pageVisualHost = currentParent as ContainerVisual;
if (pageVisualHost == null)
throw new ArgumentException(SR.Get(SRID.DocumentPageView_ParentNotDocumentPageHost), "pageVisual");
DocumentPageHost docPageHost = VisualTreeHelper.GetParent(pageVisualHost) as DocumentPageHost;
if (docPageHost == null)
throw new ArgumentException(SR.Get(SRID.DocumentPageView_ParentNotDocumentPageHost), "pageVisual");
docPageHost.PageVisual = null;
}
}
#endregion Internal Methods
//--------------------------------------------------------------------
//
// Internal Properties
//
//--------------------------------------------------------------------
#region Internal Properties
///
/// Root of visual subtree hosted by this DocumentPageHost.
///
internal Visual PageVisual
{
get
{
return _pageVisual;
}
set
{
ContainerVisual pageVisualHost;
if (_pageVisual != null)
{
pageVisualHost = VisualTreeHelper.GetParent(_pageVisual) as ContainerVisual;
Invariant.Assert(pageVisualHost != null);
pageVisualHost.Children.Clear();
this.RemoveVisualChild(pageVisualHost);
}
_pageVisual = value;
if (_pageVisual != null)
{
pageVisualHost = new ContainerVisual();
this.AddVisualChild(pageVisualHost);
pageVisualHost.Children.Add(_pageVisual);
pageVisualHost.SetValue(FlowDirectionProperty, FlowDirection.LeftToRight);
}
}
}
///
/// Internal cached offset.
///
internal Point CachedOffset;
#endregion Internal Properties
#region VisualChildren
///
/// Derived class must implement to support Visual children. The method must return
/// the child at the specified index. Index must be between 0 and GetVisualChildrenCount-1.
///
/// By default a Visual does not have any children.
///
/// Remark:
/// During this virtual call it is not valid to modify the Visual tree.
///
protected override Visual GetVisualChild(int index)
{
if (index != 0 || _pageVisual == null)
{
throw new ArgumentOutOfRangeException("index", index, SR.Get(SRID.Visual_ArgumentOutOfRange));
}
return VisualTreeHelper.GetParent(_pageVisual) as Visual;
}
///
/// Derived classes override this property to enable the Visual code to enumerate
/// the Visual children. Derived classes need to return the number of children
/// from this method.
///
/// By default a Visual does not have any children.
///
/// Remark: During this virtual method the Visual tree must not be modified.
///
protected override int VisualChildrenCount
{
get { return _pageVisual != null ? 1 : 0; }
}
#endregion VisualChildren
private Visual _pageVisual;
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- DocumentOrderQuery.cs
- FloaterBaseParaClient.cs
- WebAdminConfigurationHelper.cs
- WebPartActionVerb.cs
- ClientSettings.cs
- RecognizerInfo.cs
- TreeNodeMouseHoverEvent.cs
- DirectionalLight.cs
- EllipseGeometry.cs
- PerformanceCounterCategory.cs
- ThrowHelper.cs
- metadatamappinghashervisitor.hashsourcebuilder.cs
- FontResourceCache.cs
- ToolStripRendererSwitcher.cs
- DataSourceConverter.cs
- DelegateTypeInfo.cs
- SafeNativeMethods.cs
- ObjectTypeMapping.cs
- UIElementCollection.cs
- CreateParams.cs
- CapabilitiesPattern.cs
- GACIdentityPermission.cs
- Stackframe.cs
- ApplicationFileParser.cs
- DesignerVerbCollection.cs
- QilPatternVisitor.cs
- ReadOnlyDictionary.cs
- ListBoxAutomationPeer.cs
- SynchronizationScope.cs
- securitymgrsite.cs
- OracleBFile.cs
- SafeRegistryHandle.cs
- CmsInterop.cs
- SubclassTypeValidator.cs
- ResponseBodyWriter.cs
- PriorityQueue.cs
- IMembershipProvider.cs
- UdpSocketReceiveManager.cs
- ScriptModule.cs
- IndentTextWriter.cs
- WCFServiceClientProxyGenerator.cs
- StateMachineExecutionState.cs
- HtmlMeta.cs
- DbDataSourceEnumerator.cs
- RNGCryptoServiceProvider.cs
- ConfigurationException.cs
- Process.cs
- MulticastIPAddressInformationCollection.cs
- WinEventWrap.cs
- TransportSecurityHelpers.cs
- RepeatInfo.cs
- TextDocumentView.cs
- ListViewDataItem.cs
- GorillaCodec.cs
- UnsignedPublishLicense.cs
- ServerValidateEventArgs.cs
- SecUtil.cs
- AssemblyAssociatedContentFileAttribute.cs
- WindowsSolidBrush.cs
- Queue.cs
- XPathNavigatorReader.cs
- Soap.cs
- ThemeDictionaryExtension.cs
- AQNBuilder.cs
- AuthenticodeSignatureInformation.cs
- Compilation.cs
- Rule.cs
- NamespaceEmitter.cs
- DbExpressionRules.cs
- ProjectionPlanCompiler.cs
- FixedTextBuilder.cs
- Style.cs
- FormsAuthenticationModule.cs
- ResXResourceWriter.cs
- ConfigDefinitionUpdates.cs
- FileCodeGroup.cs
- ParentUndoUnit.cs
- XmlChildEnumerator.cs
- ListViewItemSelectionChangedEvent.cs
- Query.cs
- DataSourceSelectArguments.cs
- EpmContentDeSerializer.cs
- Error.cs
- ProbeDuplex11AsyncResult.cs
- AnnouncementDispatcherAsyncResult.cs
- RawStylusInputReport.cs
- Triplet.cs
- EndPoint.cs
- DynamicValueConverter.cs
- CngKeyCreationParameters.cs
- XmlSchemaSet.cs
- BitStream.cs
- NetSectionGroup.cs
- XMLSyntaxException.cs
- ButtonStandardAdapter.cs
- CancelEventArgs.cs
- DataGridRowAutomationPeer.cs
- PackageProperties.cs
- RegisteredExpandoAttribute.cs
- BitmapCodecInfoInternal.cs