本文整理汇总了C#中Visual类的典型用法代码示例。如果您正苦于以下问题:C# Visual类的具体用法?C# Visual怎么用?C# Visual使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Visual类属于命名空间,在下文中一共展示了Visual类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddElement
public int AddElement(Visual element)
{
if (element != null && !m_elements.Contains(element)) {
return m_elements.Add(element);
}
return -1;
}
示例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;
}
示例3: AddVisual
public void AddVisual(Visual visual)
{
visuals.Add(visual);
base.AddVisualChild(visual);
base.AddLogicalChild(visual);
}
示例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);
}
示例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;
});
}
示例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;
}
示例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();
}
示例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();
}
示例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;
}
}
}
}
}
}
示例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);
}
示例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;
}
示例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;
}
示例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();
}
示例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();
}
}
示例15: GetScreenFrom
public static Screen GetScreenFrom(Visual v)
{
var w = Window.GetWindow(v);
if (w == null)
return null;
return GetScreenFrom(w);
}