本文整理汇总了C#中IDesignerHost.CreateTransaction方法的典型用法代码示例。如果您正苦于以下问题:C# IDesignerHost.CreateTransaction方法的具体用法?C# IDesignerHost.CreateTransaction怎么用?C# IDesignerHost.CreateTransaction使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IDesignerHost
的用法示例。
在下文中一共展示了IDesignerHost.CreateTransaction方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DoInTransaction
public static object DoInTransaction(IDesignerHost theHost, string theTransactionName, TransactionAwareParammedMethod theMethod, object theParam)
{
DesignerTransaction transaction = null;
object obj2 = null;
try
{
transaction = theHost.CreateTransaction(theTransactionName);
obj2 = theMethod(theHost, theParam);
}
catch (CheckoutException exception)
{
if (exception != CheckoutException.Canceled)
{
throw exception;
}
}
catch
{
if (transaction != null)
{
transaction.Cancel();
transaction = null;
}
throw;
}
finally
{
if (transaction != null)
{
transaction.Commit();
}
}
return obj2;
}
示例2: SelectPage
/// <summary>
/// Event handler for the "Select X page" handler.
/// </summary>
/// <param name="panel"></param>
/// <param name="page"></param>
/// <returns></returns>
private static void SelectPage(IDesignerHost dh, MultiPanel panel, MultiPanelPage page)
{
DesignerTransaction dt = dh.CreateTransaction("Selected page");
MultiPanelPage oldSelectedPage = panel.SelectedPage;
panel.SelectedPage = page;
dt.Commit();
}
示例3: SmartTagTransactions
public SmartTagTransactions(string transactionname,DesignerActionList list,Control ctrl)
{
this.actionList = list;
this.ctrl = ctrl;
host = (IDesignerHost)this.actionList.GetService(typeof(IDesignerHost));
this.transaction = host.CreateTransaction(transactionname);
changeService = (IComponentChangeService)this.actionList.GetService(typeof(IComponentChangeService));
changeService.OnComponentChanging(ctrl,null);
}
示例4: DoInTransaction
public static object DoInTransaction(
IDesignerHost host,
string transactionName,
TransactionMethod transactionMethod,
object parameter)
{
DesignerTransaction transaction = null;
object RetVal = null;
try
{
// Create a new designer transaction.
transaction = host.CreateTransaction(transactionName);
// Do the task polymorphically.
RetVal = transactionMethod(host, parameter);
}
catch (CheckoutException ex) // something has gone wrong with transaction creation.
{
if (ex != CheckoutException.Canceled)
throw ex;
}
catch
{
if (transaction != null)
{
transaction.Cancel();
transaction = null; // the transaction won't commit in the finally block.
}
throw;
}
finally
{
if (transaction != null)
transaction.Commit();
}
return RetVal;
}
示例5: DoInTransaction
public static object DoInTransaction(
IDesignerHost theHost,
string theTransactionName,
TransactionAwareParammedMethod theMethod,
object theParam)
{
DesignerTransaction aTran = null;
object aRetVal = null;
try
{
aTran = theHost.CreateTransaction(theTransactionName);
aRetVal = theMethod(theHost, theParam); // do the task polymorphically
}
catch (CheckoutException theEx) // something has gone wrong with transaction creation
{
if (theEx != CheckoutException.Canceled)
throw theEx;
}
catch
{
if (aTran != null)
{
aTran.Cancel();
aTran = null; // the transaction won't commit in the finally block
}
throw;
}
finally
{
if (aTran != null)
aTran.Commit();
}
return aRetVal;
}
示例6: ConfigureGrid
internal static void ConfigureGrid(ref Grid grid, ref IDesignerHost designerhost,
ref IComponentChangeService componentChangeService,
ref DesignerTransaction dt, GridTemplate template)
{
if (template == GridTemplate.None)
return;
switch (template)
{
case GridTemplate.ProductCatalog:
{
dt = designerhost.CreateTransaction(string.Format("Configure WebGrid as {0}", template));
grid.RecordsPerRow = 3;
grid.Width = Unit.Percentage(100);
grid.Title = "Product catalog";
grid.DefaultVisibility = Visibility.None;
grid.DisplayView = DisplayView.Grid;
grid.Columns.Clear();
Text producttitle = (Text) designerhost.CreateComponent(typeof (Text));
producttitle.ColumnId = "productTitle";
producttitle.Grid = grid;
producttitle.Title = "Title";
producttitle.Visibility = Visibility.Both;
producttitle.DisplayIndex = 10;
grid.Columns.Add(producttitle);
File productImageGrid = (File) designerhost.CreateComponent(typeof (File));
productImageGrid.ColumnId = "productImageGrid";
productImageGrid.Grid = grid;
productImageGrid.Title = "Grid image";
productImageGrid.HideDetailTitle = true;
productImageGrid.NewRowInGrid = true;
productImageGrid.Visibility = Visibility.Grid;
productImageGrid.DisplayIndex = 20;
grid.Columns.Add(productImageGrid);
File productImageEdit = (File) designerhost.CreateComponent(typeof (File));
productImageEdit.ColumnId = "productImageEdit";
productImageEdit.Title = "Edit image";
productImageEdit.Grid = grid;
productImageEdit.HideDetailTitle = true;
productImageEdit.NewRowInGrid = true;
productImageEdit.Visibility = Visibility.Detail;
productImageEdit.DisplayIndex = 20;
grid.Columns.Add(productImageEdit);
Text productGridDescription = (Text) designerhost.CreateComponent(typeof (Text));
productGridDescription.ColumnId = "productGridDescription";
productGridDescription.Title = "Grid description";
productGridDescription.Grid = grid;
productGridDescription.HideDetailTitle = true;
productGridDescription.Visibility = Visibility.Grid;
productGridDescription.IsHtml = true;
productGridDescription.DisplayIndex = 30;
grid.Columns.Add(productGridDescription);
Text productEditDescription = (Text) designerhost.CreateComponent(typeof (Text));
productEditDescription.ColumnId = "productGridDescription";
productEditDescription.Grid = grid;
productEditDescription.Title = "Edit description";
productEditDescription.HideDetailTitle = true;
productEditDescription.IsHtml = true;
productEditDescription.Visibility = Visibility.Detail;
productEditDescription.DisplayIndex = 30;
grid.Columns.Add(productEditDescription);
WebGridDesignTime.SaveGridState(dt, grid, componentChangeService);
return;
}
case GridTemplate.UserRegistration:
{
grid.Width = Unit.Pixel(500);
grid.Title = "User login";
grid.DefaultVisibility = Visibility.None;
grid.DisplayView = DisplayView.Detail;
grid.AllowCancel = false;
grid.AllowUpdate = true;
grid.RecordsPerRow = 1;
grid.Columns.Clear();
Text userloginID = (Text) designerhost.CreateComponent(typeof (Text));
userloginID.ColumnId = "LoginID";
userloginID.Title = "Login ID";
userloginID.Grid = grid;
userloginID.HideDetailTitle = true;
userloginID.Visibility = Visibility.Detail;
userloginID.DisplayIndex = 10;
userloginID.Required = true;
grid.Columns.Add(userloginID);
Text userpassword = (Text) designerhost.CreateComponent(typeof (Text));
userpassword.ColumnId = "LoginPassword";
//.........这里部分代码省略.........
示例7: PersistTemplate
/// <summary>
/// Helper method to save the value of a template. This sets up all the right Undo state.
/// </summary>
/// <param name="panel"></param>
/// <param name="host"></param>
/// <param name="template"></param>
/// <param name="propertyName"></param>
private static void PersistTemplate(TabPanel panel, IDesignerHost host, ITemplate template, string propertyName)
{
PropertyDescriptor descriptor = TypeDescriptor.GetProperties(panel)[propertyName];
using (DesignerTransaction transaction = host.CreateTransaction("SetEditableDesignerRegionContent"))
{
descriptor.SetValue(panel, template);
transaction.Commit();
}
}
示例8: CreateComponentsCore
protected override IComponent[] CreateComponentsCore(IDesignerHost host)
{
IComponent[] components = base.CreateComponentsCore(host);
Control parentControl = null;
ControlDesigner parentControlDesigner = null;
TabStrip tabStrip = null;
IComponentChangeService changeSvc = (IComponentChangeService)host.GetService(typeof(IComponentChangeService));
// fish out the parent we're adding the TabStrip to.
if (components.Length > 0 && components[0] is TabStrip) {
tabStrip = components[0] as TabStrip;
ITreeDesigner tabStripDesigner = host.GetDesigner(tabStrip) as ITreeDesigner;
parentControlDesigner = tabStripDesigner.Parent as ControlDesigner;
if (parentControlDesigner != null) {
parentControl = parentControlDesigner.Control;
}
}
// Create a ControlSwitcher on the same parent.
if (host != null) {
TabPageSwitcher controlSwitcher = null;
DesignerTransaction t = null;
try {
try {
t = host.CreateTransaction("add tabswitcher");
}
catch (CheckoutException ex) {
if (ex == CheckoutException.Canceled) {
return components;
}
throw ex;
}
MemberDescriptor controlsMember = TypeDescriptor.GetProperties(parentControlDesigner)["Controls"];
controlSwitcher = host.CreateComponent(typeof(TabPageSwitcher)) as TabPageSwitcher;
if (changeSvc != null) {
changeSvc.OnComponentChanging(parentControl, controlsMember);
changeSvc.OnComponentChanged(parentControl, controlsMember, null, null);
}
Dictionary<string, object> propertyValues = new Dictionary<string, object>();
propertyValues["Location"] = new Point(tabStrip.Left, tabStrip.Bottom + 3);
propertyValues["TabStrip"] = tabStrip;
SetProperties(controlSwitcher, propertyValues, host);
}
finally {
if (t != null)
t.Commit();
}
if (controlSwitcher != null) {
IComponent[] newComponents = new IComponent[components.Length + 1];
Array.Copy(components, newComponents, components.Length);
newComponents[newComponents.Length - 1] = controlSwitcher;
return newComponents;
}
}
return components;
}
示例9: ReParentControls
private void ReParentControls(Control newParent, ArrayList controls, string transactionName, IDesignerHost host)
{
using (DesignerTransaction transaction = host.CreateTransaction(transactionName))
{
IComponentChangeService service = this.GetService(typeof(IComponentChangeService)) as IComponentChangeService;
PropertyDescriptor member = TypeDescriptor.GetProperties(newParent)["Controls"];
PropertyDescriptor descriptor2 = TypeDescriptor.GetProperties(newParent)["Location"];
Point empty = Point.Empty;
if (descriptor2 != null)
{
empty = (Point) descriptor2.GetValue(newParent);
}
if (service != null)
{
service.OnComponentChanging(newParent, member);
}
foreach (object obj2 in controls)
{
Control component = obj2 as Control;
Control parent = component.Parent;
Point point2 = Point.Empty;
InheritanceAttribute attribute = (InheritanceAttribute) TypeDescriptor.GetAttributes(component)[typeof(InheritanceAttribute)];
if ((attribute == null) || (attribute != InheritanceAttribute.InheritedReadOnly))
{
PropertyDescriptor descriptor3 = TypeDescriptor.GetProperties(component)["Location"];
if (descriptor3 != null)
{
point2 = (Point) descriptor3.GetValue(component);
}
if (parent != null)
{
if (service != null)
{
service.OnComponentChanging(parent, member);
}
parent.Controls.Remove(component);
}
newParent.Controls.Add(component);
Point point3 = Point.Empty;
if (parent != null)
{
if (parent.Controls.Contains(newParent))
{
point3 = new Point(point2.X - empty.X, point2.Y - empty.Y);
}
else
{
Point point4 = (Point) descriptor3.GetValue(parent);
point3 = new Point(point2.X + point4.X, point2.Y + point4.Y);
}
}
descriptor3.SetValue(component, point3);
if ((service != null) && (parent != null))
{
service.OnComponentChanged(parent, member, null, null);
}
}
}
if (service != null)
{
service.OnComponentChanged(newParent, member, null, null);
}
transaction.Commit();
}
}
示例10: ApplyDefaultWelcomePageStyle
internal static void ApplyDefaultWelcomePageStyle(WizardPage page, IDesignerHost dh, IComponentChangeService cc)
{
DesignerTransaction dt = null;
if (dh != null) dt = dh.CreateTransaction();
try
{
page.BackColor = Color.White;
page.Style.BackColorBlend.Clear();
TypeDescriptor.GetProperties(page)["InteriorPage"].SetValue(page, false);
TypeDescriptor.GetProperties(page)["BackColor"].SetValue(page, Color.White);
TypeDescriptor.GetProperties(page)["CanvasColor"].SetValue(page, Color.White);
TypeDescriptor.GetProperties(page.Style)["BackColor"].SetValue(page.Style, Color.White);
TypeDescriptor.GetProperties(page.Style)["BackColor2"].SetValue(page.Style, Color.Empty);
TypeDescriptor.GetProperties(page.Style)["BackgroundImage"].SetValue(page.Style, LoadWizardImage(eWizardImages.WelcomeDefault));
TypeDescriptor.GetProperties(page.Style)["BackgroundImagePosition"].SetValue(page.Style, eStyleBackgroundImage.TopLeft);
}
catch
{
dt.Cancel();
throw;
}
finally
{
if (dt != null && !dt.Canceled)
dt.Commit();
}
}
示例11: CreatePage
internal static PageSliderPage CreatePage(PageSlider parent, IDesignerHost dh, IComponentChangeService cc, ISelectionService ss)
{
DesignerTransaction dt = dh.CreateTransaction();
PageSliderPage page = null;
try
{
page = dh.CreateComponent(typeof(PageSliderPage)) as PageSliderPage;
if (cc != null)
cc.OnComponentChanging(parent, TypeDescriptor.GetProperties(parent)["Controls"]);
parent.Controls.Add(page);
if (cc != null)
cc.OnComponentChanged(parent, TypeDescriptor.GetProperties(parent)["Controls"], null, null);
if (ss != null)
ss.SetSelectedComponents(new PageSliderPage[] { page }, SelectionTypes.Replace);
TypeDescriptor.GetProperties(parent)["SelectedPage"].SetValue(parent, page);
}
catch
{
dt.Cancel();
}
finally
{
if (!dt.Canceled)
dt.Commit();
}
return page;
}
示例12: PersistTemplate
// Helper method to save the value of a template. This sets up all the right Undo state.
static void PersistTemplate(TabPanel panel, IDesignerHost host, ITemplate template, string propertyName) {
using(var transaction = host.CreateTransaction("SetEditableDesignerRegionContent")) {
var propertyInfo = panel.GetType().GetProperty(propertyName);
if(propertyInfo == null)
return;
propertyInfo.SetValue(panel, template, null);
transaction.Commit();
}
}
示例13: DeletePage
internal static void DeletePage(WizardPage page, IDesignerHost dh, IComponentChangeService cc)
{
if (page == null || !(page.Parent is Wizard))
return;
Wizard w = page.Parent as Wizard;
DesignerTransaction dt = dh.CreateTransaction();
try
{
if (cc != null)
cc.OnComponentChanging(w, TypeDescriptor.GetProperties(w)["WizardPages"]);
w.WizardPages.Remove(page);
if (cc != null)
cc.OnComponentChanged(w, TypeDescriptor.GetProperties(w)["WizardPages"], null, null);
dh.DestroyComponent(page);
}
catch
{
dt.Cancel();
}
finally
{
if (!dt.Canceled)
dt.Commit();
}
}
示例14: CreateComponentsCore
protected override IComponent[] CreateComponentsCore(IDesignerHost host)
{
IComponent[] sourceArray = base.CreateComponentsCore(host);
Control component = null;
ControlDesigner parent = null;
TabStrip strip = null;
IComponentChangeService service = (IComponentChangeService) host.GetService(typeof(IComponentChangeService));
if ((sourceArray.Length > 0) && (sourceArray[0] is TabStrip))
{
strip = sourceArray[0] as TabStrip;
ITreeDesigner designer2 = host.GetDesigner(strip) as ITreeDesigner;
parent = designer2.Parent as ControlDesigner;
if (parent != null)
{
component = parent.Control;
}
}
if (host != null)
{
TabPageSwitcher switcher = null;
DesignerTransaction transaction = null;
try
{
try
{
transaction = host.CreateTransaction("add tabswitcher");
}
catch (CheckoutException exception)
{
if (exception != CheckoutException.Canceled)
{
throw exception;
}
return sourceArray;
}
MemberDescriptor member = TypeDescriptor.GetProperties(parent)["Controls"];
switcher = host.CreateComponent(typeof(TabPageSwitcher)) as TabPageSwitcher;
if (service != null)
{
service.OnComponentChanging(component, member);
service.OnComponentChanged(component, member, null, null);
}
Dictionary<string, object> properties = new Dictionary<string, object>();
properties["Location"] = new Point(strip.Left, strip.Bottom + 3);
properties["TabStrip"] = strip;
this.SetProperties(switcher, properties, host);
}
finally
{
if (transaction != null)
{
transaction.Commit();
}
}
if (switcher != null)
{
IComponent[] destinationArray = new IComponent[sourceArray.Length + 1];
Array.Copy(sourceArray, destinationArray, sourceArray.Length);
destinationArray[destinationArray.Length - 1] = switcher;
return destinationArray;
}
}
return sourceArray;
}
示例15: CreatePage
internal static WizardPage CreatePage(Wizard parent, bool innerPage, IDesignerHost dh, IComponentChangeService cc, ISelectionService ss, eWizardStyle wizardStyle)
{
DesignerTransaction dt = dh.CreateTransaction();
WizardPage page=null;
try
{
page = dh.CreateComponent(typeof(WizardPage)) as WizardPage;
page.AntiAlias=false;
page.InteriorPage = innerPage;
if (innerPage)
{
page.PageTitle = "< Wizard step title >";
page.PageDescription = "< Wizard step description >";
}
if (wizardStyle == eWizardStyle.Default)
ApplyDefaultInnerPageStyle(page, dh, cc);
else if (wizardStyle == eWizardStyle.Office2007)
ApplyOffice2007InnerPageStyle(page, dh, cc);
//else
//{
// TypeDescriptor.GetProperties(page.Style)["BackColor"].SetValue(page.Style, Color.White);
//}
if (cc != null)
cc.OnComponentChanging(parent, TypeDescriptor.GetProperties(parent)["WizardPages"]);
parent.WizardPages.Add(page);
if (cc != null)
cc.OnComponentChanged(parent, TypeDescriptor.GetProperties(parent)["WizardPages"], null, null);
if (ss != null)
ss.SetSelectedComponents(new WizardPage[] { page }, SelectionTypes.Replace);
TypeDescriptor.GetProperties(parent)["SelectedPageIndex"].SetValue(parent, parent.WizardPages.IndexOf(page));
}
catch
{
dt.Cancel();
}
finally
{
if (!dt.Canceled)
dt.Commit();
}
return page;
}