Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / Orcas / QFE / wpf / src / Framework / MS / Internal / Ink / XamlClipboardData.cs / 1 / XamlClipboardData.cs
//----------------------------------------------------------------------------
//
// File: XamlClipboardData.cs
//
// Description:
// A base class which can copy an array of UIElement to the IDataObject as Xaml format.
// It also can retrieve the Xaml data from the IDataObject and create a UIElement array.
//
// Features:
//
// History:
// 11/17/2004 waynezen: Created
//
// Copyright (C) 2001 by Microsoft Corporation. All rights reserved.
//
//---------------------------------------------------------------------------
using System;
using System.Collections;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Markup;
using System.Security;
using System.Text;
using System.Diagnostics;
using MS.Internal.PresentationFramework; //security helper
namespace MS.Internal.Ink
{
internal class XamlClipboardData : ElementsClipboardData
{
//-------------------------------------------------------------------------------
//
// Constructors
//
//-------------------------------------------------------------------------------
#region Constructors
// The default constructor
internal XamlClipboardData() { }
// The constructor with UIElement[] as an argument
internal XamlClipboardData(UIElement[] elements) : base (elements)
{
}
// Checks if the data can be pasted.
internal override bool CanPaste(IDataObject dataObject)
{
// Check if we have Xaml data
bool hasXamlData = false;
try
{
hasXamlData = dataObject.GetDataPresent(DataFormats.Xaml, false);
}
catch ( SecurityException )
{
// If we are under the partial trust, the Xaml format will fail when it needs to be registered.
// In this case, we should just disable the Paste Xaml format content.
hasXamlData = false;
}
return hasXamlData;
}
#endregion Constructors
//--------------------------------------------------------------------------------
//
// Protected Methods
//
//-------------------------------------------------------------------------------
#region Protected Methods
// Check if we have data to be copied
protected override bool CanCopy()
{
return Elements != null && Elements.Count != 0;
}
// Convert the elements to the Xaml and copy the Xaml to the IDataObject
///
///
///
///
///
/// Critical: Calls critical method
/// SecurityHelper.ExtractAppDomainPermissionSetMinusSiteOfOrigin
///
/// We call this to ensure that the appdomain permission set is on the clipboard.
/// The Clipboard methods use this information to ensure that apps can not paste data
/// that was copied in low trust to application to a high trust application
///
[SecurityCritical]
protected override void DoCopy(IDataObject dataObject)
{
// Serialize the selected elements and add it to the data object.
StringBuilder xmlData = new StringBuilder();
foreach ( UIElement element in Elements )
{
string xml;
xml = XamlWriter.Save(element);
xmlData.Append(xml);
}
// Set the data object as XML format.
dataObject.SetData(DataFormats.Xaml, xmlData.ToString());
//
// we need to copy the permission set on the clipboard for
// the Clipboard class methods. See security note for details.
//
PermissionSet permSet = SecurityHelper.ExtractAppDomainPermissionSetMinusSiteOfOrigin();
string setString = permSet.ToString();
Debug.Assert(setString.Length > 0);
dataObject.SetData(DataFormats.ApplicationTrust, setString);
}
// Retrieves the Xaml from the IDataObject and instantiate the elements based on the Xaml
protected override void DoPaste(IDataObject dataObject)
{
ElementList = new List();
// Get the XML data from the data object.
string xml = dataObject.GetData(DataFormats.Xaml) as string;
if ( !String.IsNullOrEmpty(xml) )
{
UIElement element = XamlReader.Load(new System.Xml.XmlTextReader(new System.IO.StringReader(xml))) as UIElement;
if (element != null)
{
ElementList.Add(element);
}
}
}
#endregion Protected Methods
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
//----------------------------------------------------------------------------
//
// File: XamlClipboardData.cs
//
// Description:
// A base class which can copy an array of UIElement to the IDataObject as Xaml format.
// It also can retrieve the Xaml data from the IDataObject and create a UIElement array.
//
// Features:
//
// History:
// 11/17/2004 waynezen: Created
//
// Copyright (C) 2001 by Microsoft Corporation. All rights reserved.
//
//---------------------------------------------------------------------------
using System;
using System.Collections;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Markup;
using System.Security;
using System.Text;
using System.Diagnostics;
using MS.Internal.PresentationFramework; //security helper
namespace MS.Internal.Ink
{
internal class XamlClipboardData : ElementsClipboardData
{
//-------------------------------------------------------------------------------
//
// Constructors
//
//-------------------------------------------------------------------------------
#region Constructors
// The default constructor
internal XamlClipboardData() { }
// The constructor with UIElement[] as an argument
internal XamlClipboardData(UIElement[] elements) : base (elements)
{
}
// Checks if the data can be pasted.
internal override bool CanPaste(IDataObject dataObject)
{
// Check if we have Xaml data
bool hasXamlData = false;
try
{
hasXamlData = dataObject.GetDataPresent(DataFormats.Xaml, false);
}
catch ( SecurityException )
{
// If we are under the partial trust, the Xaml format will fail when it needs to be registered.
// In this case, we should just disable the Paste Xaml format content.
hasXamlData = false;
}
return hasXamlData;
}
#endregion Constructors
//--------------------------------------------------------------------------------
//
// Protected Methods
//
//-------------------------------------------------------------------------------
#region Protected Methods
// Check if we have data to be copied
protected override bool CanCopy()
{
return Elements != null && Elements.Count != 0;
}
// Convert the elements to the Xaml and copy the Xaml to the IDataObject
///
///
///
///
///
/// Critical: Calls critical method
/// SecurityHelper.ExtractAppDomainPermissionSetMinusSiteOfOrigin
///
/// We call this to ensure that the appdomain permission set is on the clipboard.
/// The Clipboard methods use this information to ensure that apps can not paste data
/// that was copied in low trust to application to a high trust application
///
[SecurityCritical]
protected override void DoCopy(IDataObject dataObject)
{
// Serialize the selected elements and add it to the data object.
StringBuilder xmlData = new StringBuilder();
foreach ( UIElement element in Elements )
{
string xml;
xml = XamlWriter.Save(element);
xmlData.Append(xml);
}
// Set the data object as XML format.
dataObject.SetData(DataFormats.Xaml, xmlData.ToString());
//
// we need to copy the permission set on the clipboard for
// the Clipboard class methods. See security note for details.
//
PermissionSet permSet = SecurityHelper.ExtractAppDomainPermissionSetMinusSiteOfOrigin();
string setString = permSet.ToString();
Debug.Assert(setString.Length > 0);
dataObject.SetData(DataFormats.ApplicationTrust, setString);
}
// Retrieves the Xaml from the IDataObject and instantiate the elements based on the Xaml
protected override void DoPaste(IDataObject dataObject)
{
ElementList = new List();
// Get the XML data from the data object.
string xml = dataObject.GetData(DataFormats.Xaml) as string;
if ( !String.IsNullOrEmpty(xml) )
{
UIElement element = XamlReader.Load(new System.Xml.XmlTextReader(new System.IO.StringReader(xml))) as UIElement;
if (element != null)
{
ElementList.Add(element);
}
}
}
#endregion Protected Methods
}
}
// 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
- _FtpDataStream.cs
- FixedSOMTableRow.cs
- SmiConnection.cs
- DataSpaceManager.cs
- GlyphTypeface.cs
- ExpressionTable.cs
- MobilePage.cs
- EntityDescriptor.cs
- BindingBase.cs
- SendKeys.cs
- StackSpiller.Generated.cs
- GlyphElement.cs
- InheritedPropertyChangedEventArgs.cs
- Token.cs
- TextSegment.cs
- SecurityKeyType.cs
- CodeGenerator.cs
- DnsEndpointIdentity.cs
- DecimalKeyFrameCollection.cs
- ReturnType.cs
- FutureFactory.cs
- SystemTcpConnection.cs
- RightNameExpirationInfoPair.cs
- IdentitySection.cs
- HtmlInputCheckBox.cs
- AliasGenerator.cs
- OleAutBinder.cs
- SqlException.cs
- ScriptDescriptor.cs
- BuildProvider.cs
- Listbox.cs
- ISAPIApplicationHost.cs
- UpDownBase.cs
- TextParagraphProperties.cs
- VirtualDirectoryMappingCollection.cs
- HierarchicalDataTemplate.cs
- SystemGatewayIPAddressInformation.cs
- IDQuery.cs
- CodeDOMUtility.cs
- ExplicitDiscriminatorMap.cs
- ToolbarAUtomationPeer.cs
- MSG.cs
- HandlerFactoryCache.cs
- HeaderElement.cs
- SmiEventStream.cs
- OracleDataReader.cs
- XmlSchemaType.cs
- UnsettableComboBox.cs
- SchemaElementLookUpTableEnumerator.cs
- ObjectNotFoundException.cs
- ObjectItemCollection.cs
- ManagementBaseObject.cs
- DateTimeStorage.cs
- TextSegment.cs
- HyperlinkAutomationPeer.cs
- ViewCellRelation.cs
- SchemaSetCompiler.cs
- SystemBrushes.cs
- ListViewAutomationPeer.cs
- OuterGlowBitmapEffect.cs
- GenericTypeParameterConverter.cs
- Variant.cs
- Base64Stream.cs
- SafeRegistryKey.cs
- MetaModel.cs
- CellRelation.cs
- PlatformCulture.cs
- PersonalizableAttribute.cs
- altserialization.cs
- GeneralTransformGroup.cs
- Pair.cs
- _Connection.cs
- ClientScriptItemCollection.cs
- RealProxy.cs
- EarlyBoundInfo.cs
- MailFileEditor.cs
- _emptywebproxy.cs
- XmlQuerySequence.cs
- HtmlLiteralTextAdapter.cs
- WSFederationHttpSecurityMode.cs
- ChineseLunisolarCalendar.cs
- CodeDomSerializerException.cs
- SqlDataSourceCache.cs
- PropertyOverridesDialog.cs
- GlobalizationAssembly.cs
- SqlCacheDependencyDatabase.cs
- MarkedHighlightComponent.cs
- SwitchLevelAttribute.cs
- Subtree.cs
- FixedPageProcessor.cs
- CompoundFileStreamReference.cs
- IndentTextWriter.cs
- XmlDocumentType.cs
- StandardOleMarshalObject.cs
- NetworkInformationPermission.cs
- DrawListViewItemEventArgs.cs
- RequiredFieldValidator.cs
- ExpressionEditor.cs
- SecurityTokenRequirement.cs
- ReadOnlyAttribute.cs