本文整理汇总了C#中Visual类的典型用法代码示例。如果您正苦于以下问题:C# Visual类的具体用法?C# Visual怎么用?C# Visual使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Visual类属于命名空间,在下文中一共展示了Visual类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: AddElement
public int AddElement(Visual element)
{
if (element != null && !m_elements.Contains(element)) {
return m_elements.Add(element);
}
return -1;
}
开发者ID:sohong,项目名称:greenfleet-viewer,代码行数:7,代码来源:UIContainer.cs
示例2: GetItemContainer
// Walks up the tree starting at the bottomMostVisual, until it finds the first item container for the ItemsControl
// passed as a parameter.
// In order to make sure it works with any control that derives from ItemsControl, this method makes no assumption
// about the type of that container.(it will get a ListBoxItem if it's a ListBox, a ListViewItem if it's a ListView...)
public static FrameworkElement GetItemContainer(ItemsControl itemsControl, Visual bottomMostVisual)
{
FrameworkElement itemContainer = null;
if (itemsControl != null && bottomMostVisual != null && itemsControl.Items.Count >= 1)
{
var someContainer = itemsControl.ItemContainerGenerator.ContainerFromIndex(0);
for (int i = 1; i < itemsControl.Items.Count; i++)
{
if (someContainer != null)
{
break;
}
someContainer = itemsControl.ItemContainerGenerator.ContainerFromIndex(i);
}
if (someContainer != null)
{
Type containerType = someContainer.GetType();
itemContainer = FindAncestor(containerType, bottomMostVisual);
// Make sure that the container found belongs to the items control passed as a parameter.
if (itemContainer != null && itemContainer.DataContext != null)
{
FrameworkElement itemContainerVerify = itemsControl.ItemContainerGenerator.ContainerFromItem(itemContainer.DataContext) as FrameworkElement;
if (itemContainer != itemContainerVerify)
{
itemContainer = null;
}
}
}
}
return itemContainer;
}
开发者ID:Runcy,项目名称:VidCoder,代码行数:39,代码来源:DragDropUtilities.cs
示例3: AddVisual
public void AddVisual(Visual visual)
{
visuals.Add(visual);
base.AddVisualChild(visual);
base.AddLogicalChild(visual);
}
开发者ID:ittray,项目名称:LocalDemo,代码行数:7,代码来源:DrawingCanvas.cs
示例4: SetCenterPoint
/// <summary>
/// Sets the CenterPoint of a visual to the center of a given FrameworkElement
/// </summary>
/// <param name="element">The source element</param>
/// <param name="visual">The Visual object for the source FrameworkElement</param>
private static async Task SetCenterPoint(this FrameworkElement element, Visual visual)
{
Func<bool> loadedTester = () => element.ActualWidth + element.ActualHeight < 0.1;
if (loadedTester())
{
// Wait for the loaded event and set the CenterPoint
TaskCompletionSource<object> loadedTcs = new TaskCompletionSource<object>();
RoutedEventHandler handler = null;
handler = (s, e) =>
{
loadedTcs.SetResult(null);
element.Loaded -= handler;
};
element.Loaded += handler;
await Task.WhenAny(loadedTcs.Task, Task.Delay(500));
element.Loaded -= handler;
if (loadedTester())
{
element.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
visual.CenterPoint = new Vector3((float)element.DesiredSize.Width / 2, (float)element.DesiredSize.Height / 2, 0);
return;
}
}
visual.CenterPoint = new Vector3((float)element.ActualWidth / 2, (float)element.ActualHeight / 2, 0);
}
开发者ID:Sergio0694,项目名称:UICompositionAnimations,代码行数:30,代码来源:CompositionExtensions.cs
示例5: Awake
void Awake () {
visual = transform.Find ("Visual").GetComponent <Visual> ();
transitable.Add (CharacterState.Spawn, new List<CharacterState> { CharacterState.Idle });
transitable.Add (CharacterState.Idle, new List<CharacterState> { CharacterState.Attack, CharacterState.Dead, CharacterState.Move, CharacterState.Stuck });
transitable.Add (CharacterState.Attack, new List<CharacterState> { CharacterState.Attack, CharacterState.Dead, CharacterState.Idle, CharacterState.Stuck });
transitable.Add (CharacterState.Move, new List<CharacterState> { CharacterState.Attack, CharacterState.Dead, CharacterState.Idle, CharacterState.Move, CharacterState.Stuck });
transitable.Add (CharacterState.Stuck, new List<CharacterState> { CharacterState.Attack, CharacterState.Dead, CharacterState.Idle, CharacterState.Move });
transitable.Add (CharacterState.Dead, new List<CharacterState> { });
controllable = true;
stateMachine.Add (CharacterState.Idle, () => {
CheckBlock ();
});
stateMachine.Add (CharacterState.Move, () => {
transform.position += dir * moveSpeed * Time.deltaTime;
CheckBlock ();
});
stateEnd.Add (CharacterState.Move, () => {
dir = Vector3.zero;
});
stateStart.Add (CharacterState.Attack, () => {
blurController.SetBlurs (true);
weapon.enabled = true;
trailController.gameObject.SetActive (true);
});
stateMachine.Add (CharacterState.Attack, () => {
float t = (Time.time - attackStartTime) / attackDuration;
t = Mathf.Clamp01 (t);
if (t >= 1f) {
transform.position = attackEndPoint;
RequestChangeState (CharacterState.Idle);
return;
}
t *= 2f;
var diff = attackEndPoint - attackStartPoint;
if (t < 1) {
transform.position = diff * 0.5f * t * t + attackStartPoint;
} else {
t--;
transform.position = -diff * 0.5f * (t * (t - 2f) - 1f) + attackStartPoint;
}
CheckBlock ();
});
stateEnd.Add (CharacterState.Attack, () => {
blurController.SetBlurs (false);
visual.StopAnimation ();
dir = Vector3.zero;
attackStartPoint = Vector3.zero;
attackEndPoint = Vector3.zero;
weapon.enabled = false;
trailController.gameObject.SetActive (false);
});
stateStart.Add (CharacterState.Dead, () => {
controllable = false;
});
}
开发者ID:breadceo,项目名称:hexelslashheros,代码行数:60,代码来源:Player.cs
示例6: ElementToRoot
internal static Rect ElementToRoot(Rect rectElement, Visual element, PresentationSource presentationSource)
{
GeneralTransform transformElementToRoot = element.TransformToAncestor(presentationSource.RootVisual);
Rect rectRoot = transformElementToRoot.TransformBounds(rectElement);
return rectRoot;
}
开发者ID:jugemjugem,项目名称:libShootTheSpeed,代码行数:7,代码来源:PointUtil.cs
示例7: Line
public Line(double x1, double y1, double x2, double y2)
{
LineSurface line = new LineSurface(x1, y1, x2, y2);
_visual = new Visual(line, Visual.Family.Line, null);
Born();
}
开发者ID:darwin,项目名称:silverstunts,代码行数:7,代码来源:Line.cs
示例8: Rectangle
public Rectangle(double x, double y, double w, double h)
{
RectangleSurface rectangle = new RectangleSurface(x, y, w, h);
_visual = new Visual(rectangle, Visual.Family.Rectangle, null);
Born();
}
开发者ID:darwin,项目名称:silverstunts,代码行数:7,代码来源:Rectangle.cs
示例9: GetChildren
public static IEnumerable<Visual> GetChildren(Visual parent, bool recurse = true)
{
if (parent != null)
{
int count = VisualTreeHelper.GetChildrenCount(parent);
for (int i = 0; i < count; i++)
{
// Retrieve child visual at specified index value.
var child = VisualTreeHelper.GetChild(parent, i) as Visual;
if (child != null)
{
yield return child;
if (recurse)
{
foreach (var grandChild in GetChildren(child, true))
{
yield return grandChild;
}
}
}
}
}
}
开发者ID:GreenEnergyManagement,项目名称:PerformanceCalculator,代码行数:25,代码来源:MainWindow.xaml.cs
示例10: VisualTree3DView
public VisualTree3DView(Visual visual)
{
DirectionalLight directionalLight1 = new DirectionalLight(Colors.White, new Vector3D(0, 0, 1));
DirectionalLight directionalLight2 = new DirectionalLight(Colors.White, new Vector3D(0, 0, -1));
double z = 0;
Model3D model = this.ConvertVisualToModel3D(visual, ref z);
Model3DGroup group = new Model3DGroup();
group.Children.Add(directionalLight1);
group.Children.Add(directionalLight2);
group.Children.Add(model);
this.zScaleTransform = new ScaleTransform3D();
group.Transform = this.zScaleTransform;
ModelVisual3D modelVisual = new ModelVisual3D();
modelVisual.Content = group;
Rect3D bounds = model.Bounds;
double fieldOfView = 45;
Point3D lookAtPoint = new Point3D(bounds.X + bounds.SizeX / 2, bounds.Y + bounds.SizeY / 2, bounds.Z + bounds.SizeZ / 2);
double cameraDistance = 0.5 * bounds.SizeX / Math.Tan(0.5 * fieldOfView * Math.PI / 180);
Point3D position = lookAtPoint - new Vector3D(0, 0, cameraDistance);
Camera camera = new PerspectiveCamera(position, new Vector3D(0, 0, 1), new Vector3D(0, -1, 0), fieldOfView);
this.zScaleTransform.CenterZ = lookAtPoint.Z;
this.Children.Add(modelVisual);
this.Camera = camera;
this.ClipToBounds = false;
this.Width = 500;
this.Height = 500;
this.trackballBehavior = new TrackballBehavior(this, lookAtPoint);
}
开发者ID:JonGonard,项目名称:snoopwpf,代码行数:35,代码来源:VisualTree3DView.cs
示例11: SamplePage_Loaded
private void SamplePage_Loaded(object sender, Windows.UI.Xaml.RoutedEventArgs e)
{
// Get backing visual from shadow container and interop compositor
_shadowContainer = ElementCompositionPreview.GetElementVisual(ShadowContainer);
_compositor = _shadowContainer.Compositor;
// Get CompositionImage, its sprite visual
_image = VisualTreeHelperExtensions.GetFirstDescendantOfType<CompositionImage>(ShadowContainer);
_imageVisual = _image.SpriteVisual;
// Load mask asset onto surface using helpers in SamplesCommon
_imageLoader = ImageLoaderFactory.CreateImageLoader(_compositor);
_imageMaskSurface = _imageLoader.CreateCircleSurface(200, Colors.White);
// Create surface brush for mask
CompositionSurfaceBrush mask = _compositor.CreateSurfaceBrush();
mask.Surface = _imageMaskSurface.Surface;
// Get surface brush from composition image
CompositionSurfaceBrush source = _image.SurfaceBrush as CompositionSurfaceBrush;
// Create mask brush for toggle mask functionality
_maskBrush = _compositor.CreateMaskBrush();
_maskBrush.Mask = mask;
_maskBrush.Source = source;
// Initialize toggle mask
_isMaskEnabled = false;
}
开发者ID:clarkezone,项目名称:composition,代码行数:29,代码来源:ShadowPlayground.xaml.cs
示例12: CreateBitmapFromVisuals
private BitmapSource CreateBitmapFromVisuals(Visual target, FrameworkElement cursor)
{
Rect bounds = VisualTreeHelper.GetDescendantBounds(target);
RenderTargetBitmap renderBitmap = new RenderTargetBitmap(800, 600, 96, 96, PixelFormats.Pbgra32);
DrawingVisual dv = new DrawingVisual();
using (DrawingContext ctx = dv.RenderOpen())
{
VisualBrush vb = new VisualBrush(target);
VisualBrush vbCursor = new VisualBrush(cursor);
// For linear gradient over ghost image.
////LinearGradientBrush opacityMask = new LinearGradientBrush(Color.FromArgb(255, 1, 1, 1), Color.FromArgb(0, 1, 1, 1), 30);
////ctx.PushOpacityMask(opacityMask);
vb.Opacity = _opacity;
Rect scaledBounds = new Rect(bounds.Location, new Size(bounds.Width * _scaleX, bounds.Height * _scaleY));
ctx.DrawRectangle(vbCursor, null, new Rect(0, 0, cursor.ActualWidth, cursor.ActualHeight));
ctx.DrawRectangle(vb, null, new Rect(new Point(cursor.ActualWidth, cursor.ActualHeight), scaledBounds.Size));
////ctx.Pop();
}
renderBitmap.Render(dv);
return renderBitmap;
}
开发者ID:jprofi,项目名称:MSProjects,代码行数:29,代码来源:GhostCursor.cs
示例13: Circle
public Circle(double x, double y, double r)
{
CircleSurface circle = new CircleSurface(x, y, r);
_visual = new Visual(circle, Visual.Family.Circle, null);
Born();
}
开发者ID:darwin,项目名称:silverstunts,代码行数:7,代码来源:Circle.cs
示例14: UpdateTile
// called for each visible tile
protected override void UpdateTile(Visual _tile, IntPoint ml)
{
MapControlTile2 tile = (MapControlTile2)_tile;
BitmapSource bmp;
if (m_map.Bounds.Contains(ml))
{
byte b = m_map.MapArray[ml.Y, ml.X];
if (b < 100)
bmp = m_symbolBitmapCache.GetBitmap(SymbolID.Wall, Colors.Black, false);
else
bmp = m_symbolBitmapCache.GetBitmap(SymbolID.Floor, Colors.Black, false);
}
else
{
bmp = null;
}
if (bmp != tile.Bitmap)
{
tile.Bitmap = bmp;
tile.Update();
}
}
开发者ID:tomba,项目名称:dwarrowdelf,代码行数:26,代码来源:MapControl2.cs
示例15: GetScreenFrom
public static Screen GetScreenFrom(Visual v)
{
var w = Window.GetWindow(v);
if (w == null)
return null;
return GetScreenFrom(w);
}
开发者ID:VladMorzhanov,项目名称:Study-Csharp-Projects-2015,代码行数:7,代码来源:Screen.cs
示例16: BehaviorBase
public BehaviorBase(GameObject owner)
{
_owner = owner;
_selectedBehavior = _owner.GetComponent<SelectedBehavior>();
_visual = _owner.GetComponent<Visual>();
_behaviors = _owner.GetComponent<Behaviors>();
}
开发者ID:Rfaering,项目名称:ActionTriggerGame,代码行数:7,代码来源:BehaviorBase.cs
示例17: TransformFromDevice
private static Point TransformFromDevice(this Point point, Visual visual)
{
var compositionTarget = PresentationSource.FromVisual(visual)?.CompositionTarget;
if (compositionTarget == null) throw new InvalidOperationException("Invalid visual");
var matrix = compositionTarget.TransformFromDevice;
return new Point(point.X * matrix.M11, point.Y * matrix.M22);
}
开发者ID:mjheitland,项目名称:TableTweaker,代码行数:7,代码来源:TextViewExtensions.cs
示例18: DisableOnionEffect
public static void DisableOnionEffect(Visual visual)
{
// apply to surfaces only
if (visual.family != Visual.Family.Line &&
visual.family != Visual.Family.Circle &&
visual.family != Visual.Family.Rectangle) return;
visual.content.Opacity = 1.0;
int count = visual.content.Children.Count;
bool firstLine = true;
for (int i = 0; i < count; i++)
{
if (visual.content.Children[i] is System.Windows.Shapes.Rectangle)
{
System.Windows.Shapes.Rectangle rect = visual.content.Children[i] as System.Windows.Shapes.Rectangle;
rect.Fill = Brushes.Gray;
}
if (visual.content.Children[i] is System.Windows.Shapes.Ellipse)
{
System.Windows.Shapes.Ellipse circle = visual.content.Children[i] as System.Windows.Shapes.Ellipse;
circle.Fill = Brushes.Gray;
}
if (visual.content.Children[i] is System.Windows.Shapes.Line)
{
System.Windows.Shapes.Line line = visual.content.Children[i] as System.Windows.Shapes.Line;
if (firstLine)
line.Stroke = Brushes.Gray;
else
{
line.Visibility = Visibility.Collapsed;
}
firstLine = false;
}
}
}
开发者ID:darwin,项目名称:silverstunts,代码行数:35,代码来源:Editor.cs
示例19: AttachVisuals
//-------------------------------------------------------------------------------
//
// Public Methods
//
//-------------------------------------------------------------------------------
#region Public Methods
/// <summary>
/// AttachVisual method
/// </summary>
/// <param name="visual">The stroke visual which needs to be attached</param>
/// <param name="drawingAttributes">The DrawingAttributes of the stroke</param>
public void AttachVisuals(Visual visual, DrawingAttributes drawingAttributes)
{
VerifyAccess();
EnsureRootVisual();
_renderer.AttachIncrementalRendering(visual, drawingAttributes);
}
开发者ID:JianwenSun,项目名称:cc,代码行数:20,代码来源:InkPresenter.cs
示例20: TransformToDeviceY
public static double TransformToDeviceY(Visual visual, double y)
{
var source = PresentationSource.FromVisual(visual);
if (source?.CompositionTarget != null) return y * source.CompositionTarget.TransformToDevice.M22;
return TransformToDeviceY(y);
}
开发者ID:Chandu-cuddle,项目名称:MaterialDesignInXamlToolkit,代码行数:7,代码来源:DpiHelper.cs
注:本文中的Visual类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论