本文整理汇总了C#中FrameworkElement类的典型用法代码示例。如果您正苦于以下问题:C# FrameworkElement类的具体用法?C# FrameworkElement怎么用?C# FrameworkElement使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
FrameworkElement类属于命名空间,在下文中一共展示了FrameworkElement类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FocusCore
private static void FocusCore(FrameworkElement element)
{
//System.Diagnostics.Debug.WriteLine("Focusing element " + element.ToString());
//System.Diagnostics.Debug.WriteLine(Environment.StackTrace);
if (!element.Focus())
{
//System.Diagnostics.Debug.WriteLine("- Element could not be focused, invoking in dispatcher thread");
element.Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(() => element.Focus()));
}
#if DEBUG
// no good idea, seems to block sometimes
int i = 0;
while (i < 5)
{
if (element.IsFocused)
{
//if (i > 0)
// System.Diagnostics.Debug.WriteLine("- Element is focused now in round " + i + ", leaving");
return;
}
Thread.Sleep(20);
i++;
}
//if (i >= 5)
//{
// System.Diagnostics.Debug.WriteLine("- Element is not focused after 500 ms, giving up");
//}
#endif
}
示例2: UpdateImageSource
public static void UpdateImageSource(FrameworkElement content, Grid hostBody, ImageSource imageSource, Stretch stretch)
{
if (hostBody == null || content == null)
return;
var imgRects = hostBody.Children.OfType<Rectangle>().ToArray();
for (int i = imgRects.Count() - 1; i >= 0; i--)
{
hostBody.Children.Remove(imgRects[i]);
}
if (imageSource == null)
return;
var imgBrush = new ImageBrush { ImageSource = imageSource, Stretch = stretch };
var imgRect = new Rectangle
{
OpacityMask = imgBrush
};
hostBody.Children.Add(imgRect);
ApplyForegroundToFillBinding(content, imgRect);
//var sb = new Storyboard();
//ControlHelper.CreateDoubleAnimations(sb, imgBrush, "Opacity", 0.2, 1, 75);
//hostBody.Dispatcher.BeginInvoke(sb.Begin);
}
示例3: ValidateTemplatedParent
protected override void ValidateTemplatedParent(FrameworkElement templatedParent)
{
if (templatedParent == null)
throw new ArgumentNullException("templatedParent");
if (_TargetType != null && !_TargetType.IsInstanceOfType(templatedParent))
throw new ArgumentException("Template target type mismatch.");
}
示例4: UnbindViewModelFromView
/// <summary>
/// Remove the ViewModel from the View's DataContext
/// </summary>
/// <param name="frameworkElement"></param>
/// <param name="viewModel"></param>
public void UnbindViewModelFromView(FrameworkElement frameworkElement, object viewModel)
{
if (frameworkElement.DataContext == viewModel)
{
frameworkElement.DataContext = null;
}
}
示例5: OnApplyTemplate
/// <summary>
/// Called when template should be applied to the control
/// </summary>
public override void OnApplyTemplate()
{
base.OnApplyTemplate();
_elementHorizontalTemplateFrameworkElement = this.GetTemplateChild(PreviewControl.ElementHorizontalTemplateName) as FrameworkElement;
_elementVerticalTemplateFrameworkElement = this.GetTemplateChild(PreviewControl.ElementVerticalTemplateName) as FrameworkElement;
if (_currentGridResizeDirection == GridSplitter.GridResizeDirection.Columns)
{
if (_elementHorizontalTemplateFrameworkElement != null)
{
_elementHorizontalTemplateFrameworkElement.Visibility = Visibility.Collapsed;
}
if (_elementVerticalTemplateFrameworkElement != null)
{
_elementVerticalTemplateFrameworkElement.Visibility = Visibility.Visible;
}
}
else
{
if (_elementHorizontalTemplateFrameworkElement != null)
{
_elementHorizontalTemplateFrameworkElement.Visibility = Visibility.Visible;
}
if (_elementVerticalTemplateFrameworkElement != null)
{
_elementVerticalTemplateFrameworkElement.Visibility = Visibility.Collapsed;
}
}
}
示例6: CheckArgument
private static void CheckArgument(FrameworkElement element)
{
if (element == null)
{
throw new ArgumentNullException("element");
}
}
示例7: AddError
internal static void AddError (FrameworkElement element, ValidationError error)
{
var errors = GetErrorsCore (element);
errors.Add (error);
if (errors.Count == 1)
SetHasError (element, true);
}
示例8: CreateAnimation
public override IEnumerable<Timeline> CreateAnimation(FrameworkElement element)
{
double startRotation = 0.0;
double endRotation;
if (StartRotation.HasValue)
startRotation = StartRotation.Value;
else
{
var compositeTransform = element.RenderTransform as CompositeTransform;
if (compositeTransform != null)
startRotation = compositeTransform.Rotation;
}
if (EndRotation.HasValue)
endRotation = EndRotation.Value;
else
endRotation = startRotation + 360.0;
return new Timeline[]
{
element.AnimatePointProperty(AnimationProperty.RenderTransformOrigin)
.AddDiscreteKeyFrame(0.0, new Point(0.5, 0.5)),
element.AnimateProperty(AnimationProperty.Rotation)
.AddEasingKeyFrame(0.0, startRotation)
.AddEasingKeyFrame(Duration, endRotation, Easing)
.AddDiscreteKeyFrame(Duration, startRotation),
};
}
示例9: UnbindViewModelFromView
/// <summary>
/// if the view model implements the IParentDataContextAwareViewModel interface then the parents view will be disconnected.
/// </summary>
/// <param name="frameworkElement"></param>
/// <param name="viewModel"></param>
public void UnbindViewModelFromView(FrameworkElement frameworkElement, object viewModel)
{
if (viewModel is IParentDataContextAwareViewModel)
{
frameworkElement.Loaded -= InjectParentDataContextOnload;
}
}
示例10: CreateAnimation
public override IEnumerable<Timeline> CreateAnimation(FrameworkElement element)
{
var transform = GetTransform(element);
var list = new List<Timeline>
{
element.AnimateProperty(AnimationProperty.Opacity)
.AddEasingKeyFrame(0.0, 0)
.AddEasingKeyFrame(Duration, 1),
};
if (Math.Abs(DistanceX) > 0)
{
list.Add(
element.AnimateProperty(AnimationProperty.TranslateX)
.AddEasingKeyFrame(0.0, transform.TranslateX + DistanceX)
.AddEasingKeyFrame(Duration, transform.TranslateX, new CubicEase()));
}
if (Math.Abs(DistanceY) > 0)
{
list.Add(
element.AnimateProperty(AnimationProperty.TranslateY)
.AddEasingKeyFrame(0.0, transform.TranslateY + DistanceY)
.AddEasingKeyFrame(Duration, transform.TranslateY, new CubicEase()));
}
return list;
}
示例11: SetupEffect
public virtual void SetupEffect(FrameworkElement parent, ref PositionColoredTextured[] verts, float zOrder, bool adaptVertsToBrushTexture)
{
if (!UpdateBounds(ref verts))
return;
float w = _vertsBounds.Width;
float h = _vertsBounds.Height;
float xoff = _vertsBounds.X;
float yoff = _vertsBounds.Y;
if (adaptVertsToBrushTexture)
for (int i = 0; i < verts.Length; i++)
{
PositionColoredTextured vert = verts[i];
float x = vert.X;
float u = x - xoff;
u /= w;
float y = vert.Y;
float v = y - yoff;
v /= h;
if (u < 0) u = 0;
if (u > 1) u = 1;
if (v < 0) v = 0;
if (v > 1) v = 1;
unchecked
{
Color4 color = ColorConverter.FromColor(Color.White);
vert.Color = color.ToBgra();
}
vert.Tu1 = u;
vert.Tv1 = v;
vert.Z = zOrder;
verts[i] = vert;
}
}
示例12: Helper
public Helper(FrameworkElement obj, DependencyProperty property, Action<object, object> changed, object currentValue)
{
this.obj = obj;
this.property = property;
this.changed = changed;
this.currentValue = currentValue;
}
示例13: SkipToFill
public void SkipToFill(FrameworkElement target)
{
if (Storyboard != null)
{
Storyboard.SkipToFill(target);
}
}
示例14: UpdateClipSize
public static void UpdateClipSize(FrameworkElement element, Size clipSize)
{
if (element != null)
{
RectangleGeometry clipRectangle = null;
if (element.Clip == null)
{
clipRectangle = new RectangleGeometry();
element.Clip = clipRectangle;
}
else
{
if (element.Clip is RectangleGeometry)
{
clipRectangle = (RectangleGeometry)element.Clip;
}
}
if (clipRectangle != null)
{
clipRectangle.Rect = new Rect(new Point(0, 0), clipSize);
}
}
}
示例15: CreateAnimation
public override IEnumerable<Timeline> CreateAnimation(FrameworkElement element)
{
var transform = GetTransform(element);
return new Timeline[]
{
element.AnimatePointProperty(AnimationProperty.RenderTransformOrigin)
.AddDiscreteKeyFrame(0.0, new Point(0, 1)),
element.AnimateProperty(AnimationProperty.Opacity)
.AddEasingKeyFrame(0.0, 0)
.AddEasingKeyFrame(Duration*0.6, 1),
element.AnimateProperty(AnimationProperty.TranslateX)
.AddEasingKeyFrame(0.0, transform.TranslateX + 700)
.AddEasingKeyFrame(Duration*0.6, transform.TranslateX - 30, new QuadraticEase())
.AddEasingKeyFrame(Duration*0.8, transform.TranslateX),
element.AnimateProperty(AnimationProperty.SkewX)
.AddEasingKeyFrame(0.0, -30)
.AddEasingKeyFrame(Duration*0.6, 30)
.AddEasingKeyFrame(Duration*0.8, -15)
.AddEasingKeyFrame(Duration, 0),
};
}