当前位置: 首页>>代码示例>>C#>>正文


C# DesignItem.OpenGroup方法代码示例

本文整理汇总了C#中DesignItem.OpenGroup方法的典型用法代码示例。如果您正苦于以下问题:C# DesignItem.OpenGroup方法的具体用法?C# DesignItem.OpenGroup怎么用?C# DesignItem.OpenGroup使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DesignItem的用法示例。


在下文中一共展示了DesignItem.OpenGroup方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ApplyTransform

		public static void ApplyTransform(DesignItem designItem, Transform transform, bool relative = true)
		{
			var changeGroup = designItem.OpenGroup("Apply Transform");
			
			Transform oldTransform = null;
			if (designItem.Properties.GetProperty(FrameworkElement.RenderTransformProperty).IsSet) {
				oldTransform = designItem.Properties.GetProperty(FrameworkElement.RenderTransformProperty).ValueOnInstance as Transform;
			}
			
			if (oldTransform is MatrixTransform) {
				var mt = oldTransform as MatrixTransform;
				var tg = new TransformGroup();
				if (mt.Matrix.OffsetX != 0 && mt.Matrix.OffsetY != 0)
					tg.Children.Add(new TranslateTransform(){ X = mt.Matrix.OffsetX, Y = mt.Matrix.OffsetY });
				if (mt.Matrix.M11 != 0 && mt.Matrix.M22 != 0)
					tg.Children.Add(new ScaleTransform(){ ScaleX = mt.Matrix.M11, ScaleY = mt.Matrix.M22 });

				var angle = Math.Atan2(mt.Matrix.M21, mt.Matrix.M11) * 180 / Math.PI;
				if (angle != 0)
					tg.Children.Add(new RotateTransform(){ Angle = angle });
				//if (mt.Matrix.M11 != 0 && mt.Matrix.M22 != 0)
				//	tg.Children.Add(new SkewTransform(){ ScaleX = mt.Matrix.M11, ScaleY = mt.Matrix.M22 });
			} else if (oldTransform != null && oldTransform.GetType() != transform.GetType()) {
				var tg = new TransformGroup();
				var tgDes = designItem.Services.Component.RegisterComponentForDesigner(tg);
				tgDes.ContentProperty.CollectionElements.Add(designItem.Services.Component.GetDesignItem(oldTransform));
				designItem.Properties.GetProperty(FrameworkElement.RenderTransformProperty).SetValue(tg);
				oldTransform = tg;
			}
			
			
			
			if (transform is RotateTransform) {
				var rotateTransform = transform as RotateTransform;
				
				if (oldTransform is RotateTransform || oldTransform == null) {
					if (rotateTransform.Angle != 0) {
						designItem.Properties.GetProperty(FrameworkElement.RenderTransformProperty).SetValue(transform);
						var angle = rotateTransform.Angle;
						if (relative && oldTransform != null) {
							angle = rotateTransform.Angle + ((RotateTransform)oldTransform).Angle;
						}
						designItem.Properties.GetProperty(FrameworkElement.RenderTransformProperty).Value.Properties.GetProperty(RotateTransform.AngleProperty).SetValue(angle);
						if (rotateTransform.CenterX != 0.0)
							designItem.Properties.GetProperty(FrameworkElement.RenderTransformProperty).Value.Properties.GetProperty(RotateTransform.CenterXProperty).SetValue(rotateTransform.CenterX);
						if (rotateTransform.CenterY != 0.0)
							designItem.Properties.GetProperty(FrameworkElement.RenderTransformProperty).Value.Properties.GetProperty(RotateTransform.CenterYProperty).SetValue(rotateTransform.CenterY);
						
						if (oldTransform == null)
							designItem.Properties.GetProperty(FrameworkElement.RenderTransformOriginProperty).SetValue(new Point(0.5, 0.5));
					}
					else {
						designItem.Properties.GetProperty(FrameworkElement.RenderTransformProperty).Reset();
						designItem.Properties.GetProperty(FrameworkElement.RenderTransformOriginProperty).Reset();
					}
				} else if (oldTransform is TransformGroup) {
					var tg = oldTransform as TransformGroup;
					var rot = tg.Children.FirstOrDefault(x=> x is RotateTransform);
					if  (rot != null) {
						designItem.Services.Component.GetDesignItem(tg).ContentProperty.CollectionElements.Remove(designItem.Services.Component.GetDesignItem(rot));
					}
					if (rotateTransform.Angle != 0) {
						var des = designItem.Services.Component.GetDesignItem(transform);
						if (des == null)
							des = designItem.Services.Component.RegisterComponentForDesigner(transform);
						designItem.Services.Component.GetDesignItem(tg).ContentProperty.CollectionElements.Add(des);
						if (oldTransform == null)
							designItem.Properties.GetProperty(FrameworkElement.RenderTransformOriginProperty).SetValue(new Point(0.5, 0.5));
					}
				} else {
						if (rotateTransform.Angle != 0) {
							designItem.Properties.GetProperty(FrameworkElement.RenderTransformProperty).SetValue(transform);
							if (oldTransform == null)
								designItem.Properties.GetProperty(FrameworkElement.RenderTransformOriginProperty).SetValue(new Point(0.5, 0.5));
					}
				}
			}
		
			((DesignPanel) designItem.Services.DesignPanel).AdornerLayer.UpdateAdornersForElement(designItem.View, true);
			
			changeGroup.Commit();
		}
开发者ID:modulexcite,项目名称:WpfDesigner,代码行数:82,代码来源:ModelTools.cs


注:本文中的DesignItem.OpenGroup方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。