本文整理汇总了C#中FrameworkElement.GetValue方法的典型用法代码示例。如果您正苦于以下问题:C# FrameworkElement.GetValue方法的具体用法?C# FrameworkElement.GetValue怎么用?C# FrameworkElement.GetValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FrameworkElement
的用法示例。
在下文中一共展示了FrameworkElement.GetValue方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetPropertyBinding
public static SetterValueBindingHelper GetPropertyBinding(FrameworkElement element)
{
if (null == element)
{
throw new ArgumentNullException("element");
}
return (SetterValueBindingHelper)element.GetValue(PropertyBindingProperty);
}
示例2: ParseMetadata
/// <summary>
/// Parse metadata from a target FrameworkElement. This will cache the metadata on the element as an attached property.
/// </summary>
/// <param name="element">The target FrameworkElement to pull metadata from.</param>
/// <param name="forceUpdate">If set, will not pull metadata from cache.</param>
/// <param name="entity">The entity used.</param>
/// <param name="bindingExpression">The bindingExpression used.</param>
/// <returns>Returns the metadata associated with the element. Will be null if no metadata was found.</returns>
internal static ValidationMetadata ParseMetadata(FrameworkElement element, bool forceUpdate, out object entity, out BindingExpression bindingExpression)
{
entity = null;
bindingExpression = null;
if (element == null)
{
return null;
}
if (!forceUpdate)
{
ValidationMetadata existingVMD = element.GetValue(ValidationMetadataProperty) as ValidationMetadata;
if (existingVMD != null)
{
return existingVMD;
}
}
BindingExpression be = null;
FieldInfo[] fields = element.GetType().GetFields(BindingFlags.Static | BindingFlags.Public | BindingFlags.FlattenHierarchy);
foreach (FieldInfo field in fields)
{
if (field.FieldType == typeof(DependencyProperty))
{
// Found a dependency property
be = element.GetBindingExpression((DependencyProperty)field.GetValue(null));
if (be != null && be.ParentBinding != null && be.ParentBinding.Path != null)
{
// Found a BindingExpression, ensure it has valid data
entity = be.DataItem != null ? be.DataItem : element.DataContext;
if (entity != null)
{
if (be.ParentBinding.Mode == BindingMode.TwoWay)
{
bindingExpression = be;
// A twoway binding will be automatically chosen and the rest ignored
break;
}
// Perform an arbitrary sort on path (string), so the same dependency property is chosen consistently.
// Reflection ordering is not deterministic and if we just pick the first, we could be
// matched with different dependency properties depending on the run.
if (bindingExpression == null || string.Compare(be.ParentBinding.Path.Path, bindingExpression.ParentBinding.Path.Path, StringComparison.Ordinal) < 0)
{
bindingExpression = be;
}
}
}
}
}
if (bindingExpression != null)
{
ValidationMetadata newVMD = ParseMetadata(bindingExpression.ParentBinding.Path.Path, entity);
element.SetValue(ValidationMetadataProperty, newVMD);
return newVMD;
}
return null;
}
示例3: Register
public static void Register(FrameworkElement obj, DependencyProperty property, Action<object, object> changed)
{
if (helpers == null)
helpers = new List<Helper>();
var helper = new Helper(obj, property, changed, obj.GetValue(property));
var binding = new Binding();
binding.Path = new PropertyPath("Property");
binding.Source = helper;
binding.Mode = BindingMode.TwoWay;
obj.SetBinding(property, binding);
helpers.Add(helper);
}
示例4: GetOrCreateBindingsList
private IList<IMvxUpdateableBinding> GetOrCreateBindingsList(FrameworkElement attachedObject)
{
var existing = attachedObject.GetValue(BindingsListProperty) as IList<IMvxUpdateableBinding>;
if (existing != null)
return existing;
// attach the list
var newList = new List<IMvxUpdateableBinding>();
attachedObject.SetValue(BindingsListProperty, newList);
// create a binding watcher for the list
#if WINDOWS_PHONE || WINDOWS_WPF
var binding = new System.Windows.Data.Binding();
#endif
#if NETFX_CORE
var binding = new Windows.UI.Xaml.Data.Binding();
#endif
bool attached = false;
Action attachAction = () =>
{
if (attached)
return;
BindingOperations.SetBinding(attachedObject, DataContextWatcherProperty, binding);
attached = true;
};
Action detachAction = () =>
{
if (!attached)
return;
#if WINDOWS_PHONE || NETFX_CORE
attachedObject.ClearValue(DataContextWatcherProperty);
#else
BindingOperations.ClearBinding(attachedObject, DataContextWatcherProperty);
#endif
attached = false;
};
attachAction();
attachedObject.Loaded += (o, args) =>
{
attachAction();
};
attachedObject.Unloaded += (o, args) =>
{
detachAction();
};
return newList;
}
示例5: Register
/// <summary>Registers an event callback on a given dependency property. </summary>
/// <param name="frameworkElement">The source framework element. </param>
/// <param name="property">The property to register the callback for. </param>
/// <param name="handler">The event handler. </param>
public static void Register(FrameworkElement frameworkElement, DependencyProperty property, Action<object, object> handler)
{
if (_dependencyPropertyRegistrations == null)
_dependencyPropertyRegistrations = new List<DependencyPropertyRegistration>();
var helper = new DependencyPropertyRegistration(
frameworkElement, property, handler, frameworkElement.GetValue(property));
var binding = new Binding();
binding.Path = new PropertyPath("Property");
binding.Source = helper;
binding.Mode = BindingMode.TwoWay;
frameworkElement.SetBinding(property, binding);
_dependencyPropertyRegistrations.Add(helper);
}
示例6: ExecuteOnFirstLoad
/// <summary>
/// Executes the handler the fist time the element is loaded.
/// </summary>
/// <param name="element">The element.</param>
/// <param name="handler">The handler.</param>
public static void ExecuteOnFirstLoad(FrameworkElement element, Action<FrameworkElement> handler)
{
if ((bool) element.GetValue(PreviouslyAttachedProperty)) return;
element.SetValue(PreviouslyAttachedProperty, true);
ExecuteOnLoad(element, handler);
}
示例7: ExecuteOnLoad
/// <summary>
/// Executes the handler immediately if the element is loaded, otherwise wires it to the Loaded event.
/// </summary>
/// <param name="element">The element.</param>
/// <param name="handler">The handler.</param>
/// <returns>true if the handler was executed immediately; false otherwise</returns>
public static bool ExecuteOnLoad(FrameworkElement element, RoutedEventHandler handler)
{
#if SILVERLIGHT
if ((bool)element.GetValue(IsLoadedProperty))
#elif WinRT
if (IsElementLoaded(element))
#else
if(element.IsLoaded)
#endif
{
handler(element, new RoutedEventArgs());
return true;
}
else
{
RoutedEventHandler loaded = null;
loaded = (s, e) =>
{
#if SILVERLIGHT
element.SetValue(IsLoadedProperty, true);
#endif
handler(s, e);
element.Loaded -= loaded;
};
element.Loaded += loaded;
return false;
}
}
示例8: GetTextHintingMode
public static TextHintingMode GetTextHintingMode (FrameworkElement target)
{
return (TextHintingMode) target.GetValue (TextOptions.TextHintingModeProperty);
}
示例9: GetIdle
public static AnimationDefinition GetIdle(FrameworkElement element)
{
return (AnimationDefinition) element.GetValue(IdleProperty);
}
示例10: GetOpen
public static AnimationDefinition GetOpen(FrameworkElement element)
{
return (AnimationDefinition) element.GetValue(OpenProperty);
}
示例11: CreateStoryboard
private static Storyboard CreateStoryboard(
FrameworkElement target,
DependencyProperty animatingDependencyProperty,
string propertyPath,
ref object toValue,
TimeSpan durationTimeSpan)
{
object fromValue = target.GetValue(animatingDependencyProperty);
double fromDoubleValue;
double toDoubleValue;
DateTime fromDateTime;
DateTime toDateTime;
Storyboard storyBoard = new Storyboard();
Storyboard.SetTarget(storyBoard, target);
Storyboard.SetTargetProperty(storyBoard, propertyPath);
if ((fromValue != null && toValue != null))
{
if (ValueHelper.TryConvert(fromValue, out fromDoubleValue) && ValueHelper.TryConvert(toValue, out toDoubleValue))
{
DoubleAnimation doubleAnimation = new DoubleAnimation();
doubleAnimation.Duration = durationTimeSpan;
doubleAnimation.To = ValueHelper.ToDouble(toValue);
toValue = doubleAnimation.To;
storyBoard.Children.Add(doubleAnimation);
}
else if (ValueHelper.TryConvert(fromValue, out fromDateTime) && ValueHelper.TryConvert(toValue, out toDateTime))
{
ObjectAnimationUsingKeyFrames keyFrameAnimation = new ObjectAnimationUsingKeyFrames();
keyFrameAnimation.Duration = durationTimeSpan;
long intervals = (long)(durationTimeSpan.TotalSeconds * KeyFramesPerSecond);
if (intervals < 2L)
{
intervals = 2L;
}
IEnumerable<TimeSpan> timeSpanIntervals =
ValueHelper.GetTimeSpanIntervalsInclusive(durationTimeSpan, intervals);
IEnumerable<DateTime> dateTimeIntervals =
ValueHelper.GetDateTimesBetweenInclusive(fromDateTime, toDateTime, intervals);
IEnumerable<DiscreteObjectKeyFrame> keyFrames =
EnumerableFunctions.Zip(
dateTimeIntervals,
timeSpanIntervals,
(dateTime, timeSpan) => new DiscreteObjectKeyFrame() { Value = dateTime, KeyTime = timeSpan });
foreach (DiscreteObjectKeyFrame keyFrame in keyFrames)
{
keyFrameAnimation.KeyFrames.Add(keyFrame);
toValue = keyFrame.Value;
}
storyBoard.Children.Add(keyFrameAnimation);
}
}
if (storyBoard.Children.Count == 0)
{
ObjectAnimationUsingKeyFrames keyFrameAnimation = new ObjectAnimationUsingKeyFrames();
DiscreteObjectKeyFrame endFrame = new DiscreteObjectKeyFrame() { Value = toValue, KeyTime = new TimeSpan(0, 0, 0) };
keyFrameAnimation.KeyFrames.Add(endFrame);
storyBoard.Children.Add(keyFrameAnimation);
}
return storyBoard;
}
示例12: GetIsHeaderOf
public static TreeViewItem GetIsHeaderOf(FrameworkElement element)
{
if (element == null)
{
throw new ArgumentNullException("element");
}
return element.GetValue(IsHeaderOfProperty) as TreeViewItem;
}
示例13: SuspendScroll
private static void SuspendScroll(object sender, RoutedEventArgs e)
{
var blockingElement = sender as FrameworkElement;
// Determines the parent Panorama/Pivot control
if (_internalPanningControl == null)
#if NETFX_CORE
_internalPanningControl = FindAncestor(blockingElement, p => p is Hub || p is FlipView) as FrameworkElement;
_internalPanningControl = FindAncestor(blockingElement, p => p is Pivot || p is Hub || p is FlipView) as FrameworkElement;
#elif SILVERLIGHT
_internalPanningControl = FindAncestor(blockingElement, p => p is Pivot || p is Panorama) as FrameworkElement;
#endif
if (_internalPanningControl != null && (bool)_internalPanningControl.GetValue(IsScrollSuspendedProperty))
return;
// When the user touches the control...
var originalSource = e.OriginalSource as DependencyObject;
if (FindAncestor(originalSource, dobj => dobj == blockingElement) != blockingElement)
return;
// Mark the parent Panorama/Pivot for scroll suspension
// and register for touch frame events
_internalPanningControl?.SetValue(IsScrollSuspendedProperty, true);
#if NETFX_CORE
CoreWindow.GetForCurrentThread().PointerReleased += PreventScrollBinding_PointerReleased;
#elif SILVERLIGHT
Touch.FrameReported += TouchFrameReported;
#endif
if (blockingElement != null)
blockingElement.IsHitTestVisible = true;
if (_internalPanningControl != null)
_internalPanningControl.IsHitTestVisible = false;
}
示例14: TextEditor
//-----------------------------------------------------
//
// Constructors
//
//-----------------------------------------------------
#region Constructors
/// <summary>
/// Initialize the TextEditor
/// </summary>
/// <param name="textContainer">
/// TextContainer representing a content to edit.
/// </param>
/// <param name="uiScope">
/// FrameworkElement on which all events for the user interaction will be
/// processed.
/// </param>
/// <param name="isUndoEnabled">
/// If true the TextEditor will enable undo support
/// </param>
internal TextEditor(ITextContainer textContainer, FrameworkElement uiScope, bool isUndoEnabled)
{
// Validate parameters
Invariant.Assert(uiScope != null);
// Set non-zero property defaults.
_acceptsRichContent = true;
// Attach the editor instance to the scope
_textContainer = textContainer;
_uiScope = uiScope;
// Enable undo manager for this uiScope
if (isUndoEnabled && _textContainer is TextContainer)
{
((TextContainer)_textContainer).EnableUndo(_uiScope);
}
// Create TextSelection and link it to text container
_selection = new TextSelection(this);
textContainer.TextSelection = _selection;
// Create DragDropProcess
//
_dragDropProcess = new TextEditorDragDrop._DragDropProcess(this);
// By default we use IBeam cursor
_cursor = Cursors.IBeam;
// Add InputLanguageChanged event handler
TextEditorTyping._AddInputLanguageChangedEventHandler(this);
// Listen to both TextContainer.EndChanging and TextContainer.Changed events
TextContainer.Changed += new TextContainerChangedEventHandler(OnTextContainerChanged);
// Add IsEnabled event handler for cleaning the caret element when uiScope is disabled
_uiScope.IsEnabledChanged += new DependencyPropertyChangedEventHandler(OnIsEnabledChanged);
// Attach this instance of text editor to its uiScope
_uiScope.SetValue(TextEditor.InstanceProperty, this);
// The IsSpellerEnabled property might have been set before this
// TextEditor was instantiated -- check if we need to rev
// up speller support.
if ((bool)_uiScope.GetValue(SpellCheck.IsEnabledProperty))
{
SetSpellCheckEnabled(true);
SetCustomDictionaries(true);
}
// If no IME/TextServices are installed, we have no native reasources
// to clean up at Finalizer.
if (!TextServicesLoader.ServicesInstalled)
{
GC.SuppressFinalize(this);
}
}