public GetValue ( |
||
dp | ||
리턴 | object |
/// <summary> /// Gets the value of the <strong>AttachedDataContext</strong> attached property from a given /// <see cref="DependencyObject"/> object. /// </summary> /// <param name="obj">The object from which to read the property value.</param> /// <return>The value of the <strong>AttachedDataContext</strong> attached property.</return> /// <exception cref="ArgumentNullException"> /// <paramref name="obj"/> is <see langword="null"/>. /// </exception> public static object GetAttachedDataContext(DependencyObject obj) { if (obj == null) throw new ArgumentNullException("obj"); return obj.GetValue(AttachedDataContextProperty); }
public static bool SetPropertyValueOnTarget(DependencyObject target, string propertyName,bool ballowed) { var prop = GetDependencyProperty(target, propertyName); if (target.GetValue(prop) == null || target.GetValue(prop).GetType() == typeof(string)) { if (!ballowed) { target.SetValue(prop, String.Empty); } return true; } if (target.GetValue(prop).GetType() == typeof(bool)) { target.SetValue(prop, ballowed); return true; } if (target.GetValue(prop).GetType() == typeof(Visibility)) { if (ballowed) { target.SetValue(prop, Visibility.Visible); } else { target.SetValue(prop, Visibility.Collapsed); } return true; } return false; }
// ------------------------------------------------------------------ // Constructor. // Remarks - the pageWidth parameter can be used to limit column // properties if the element is a FlowDocument. // ------------------------------------------------------------------ internal ColumnPropertiesGroup(DependencyObject o) { _columnWidth = (double)o.GetValue(FlowDocument.ColumnWidthProperty); _columnGap = (double)o.GetValue(FlowDocument.ColumnGapProperty); _columnRuleWidth = (double)o.GetValue(FlowDocument.ColumnRuleWidthProperty); _columnRuleBrush = (Brush)o.GetValue(FlowDocument.ColumnRuleBrushProperty); _isColumnWidthFlexible = (bool)o.GetValue(FlowDocument.IsColumnWidthFlexibleProperty); }
public static PushBindingCollection GetPushBindings(DependencyObject obj) { if (obj.GetValue(PushBindingsProperty) == null) { obj.SetValue(PushBindingsProperty, new PushBindingCollection(obj)); } return (PushBindingCollection)obj.GetValue(PushBindingsProperty); }
private static void OnPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { var sourceValue = d.GetValue(ExtendedBinding.SourceProperty); var targetValue = d.GetValue(ExtendedBinding.TargetProperty); if (e.Property == ExtendedBinding.SourceProperty && !object.ReferenceEquals(sourceValue, targetValue)) d.SetValue(ExtendedBinding.TargetProperty, sourceValue); else if (e.Property == ExtendedBinding.TargetProperty && !object.ReferenceEquals(sourceValue, targetValue)) d.SetValue(ExtendedBinding.SourceProperty, targetValue); }
internal static Typeface GetModifiedTypeface(DependencyObject element, FontFamily fontFamily) { Debug.Assert(element != null); FontStyle fontStyle = (FontStyle) element.GetValue(TextElement.FontStyleProperty); FontWeight fontWeight = (FontWeight) element.GetValue(TextElement.FontWeightProperty); FontStretch fontStretch = (FontStretch) element.GetValue(TextElement.FontStretchProperty); return new Typeface(fontFamily, fontStyle, fontWeight, fontStretch); }
internal static List<ConnectionPoint> GetConnectionPoints(DependencyObject obj) { if (obj is StartSymbol) { return (List<ConnectionPoint>)obj.GetValue(StateContainerEditor.ConnectionPointsProperty); } if (!(obj is VirtualizedContainerService.VirtualizingContainer)) { obj = VisualTreeUtils.FindVisualAncestor<VirtualizedContainerService.VirtualizingContainer>(obj); } return (List<ConnectionPoint>)obj.GetValue(StateContainerEditor.ConnectionPointsProperty); }
private static void OnTimeChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) { DoubleAnimation animation = (DoubleAnimation)sender; double time = GetTime(animation); Thickness from = (Thickness)sender.GetValue(FromProperty); Thickness to = (Thickness)sender.GetValue(ToProperty); DependencyProperty targetProperty = (DependencyProperty)sender.GetValue(TargetPropertyProperty); DependencyObject target = (DependencyObject)sender.GetValue(TargetProperty); target.SetValue(targetProperty, new Thickness((to.Left - from.Left) * time + from.Left, (to.Top - from.Top) * time + from.Top, (to.Right - from.Right) * time + from.Right, (to.Bottom - from.Bottom) * time + from.Bottom)); }
public static AnimationClock AnimateEasingEquation( DependencyObject element, DependencyProperty prop, EasingFunction function, double to, int durationMS) { double from = double.IsNaN((double)element.GetValue(prop)) ? 0 : (double)element.GetValue(prop); AnimationTimeline timeline = GetEasingAnimation(function, EasingMode.EaseIn, from, to, durationMS); return Animate(element, prop, timeline, durationMS, null, null, null); }
public static string GetBoundPassword(DependencyObject d) { var box = d as PasswordBox; if (box == null) return (string) d.GetValue(BoundPasswordProperty); box.PasswordChanged -= PasswordChanged; box.PasswordChanged += PasswordChanged; var password = box.ToString(); if (password != null) SetSelection(box, password.Length, 0); return (string)d.GetValue(BoundPasswordProperty); }
public static bool GetHeaderSort(DependencyObject obj) { if (obj == null) throw new ArgumentNullException("obj"); return (bool)obj.GetValue(HeaderSortProperty); }
/// <summary> /// Gets the value of the <see cref="ErrorMessageProperty"/> property. /// </summary> /// <param name="dependencyObject"> /// The dependency object. /// </param> /// <returns> /// The property value. /// </returns> /// <exception cref="ArgumentNullException"> /// The <paramref name="dependencyObject"/> parameter is null. /// </exception> public static string GetErrorMessage(DependencyObject dependencyObject) { if (dependencyObject == null) throw new ArgumentNullException("dependencyObject"); return (string)dependencyObject.GetValue(ErrorMessageProperty); }
private void OnUploadFillRule(object sender, System.Windows.Input.ExecutedRoutedEventArgs e) { Windows.DependencyObject d = sender as Windows.DependencyObject; RuleFileManager manager = (d == null ? null : d.GetValue(Windows.FrameworkElement.DataContextProperty) as RuleFileManager); System.Threading.ThreadPool.QueueUserWorkItem(RuleFileUploadWorker, manager); }
private void CanUploadFillRule(object sender, System.Windows.Input.CanExecuteRoutedEventArgs e) { Windows.DependencyObject d = sender as Windows.DependencyObject; RuleFileManager manager = (d == null ? null : d.GetValue(Windows.FrameworkElement.DataContextProperty) as RuleFileManager); e.CanExecute = manager != null && manager.IsUploading == false; }
// // Attached Property Accessor Methods // public static bool GetIsVirtualizing (DependencyObject o) { if (o == null) throw new ArgumentNullException ("o"); return (bool) o.GetValue (VirtualizingStackPanel.IsVirtualizingProperty); }
public static VirtualizationMode GetVirtualizationMode (DependencyObject element) { if (element == null) throw new ArgumentNullException ("element"); return (VirtualizationMode) element.GetValue (VirtualizingStackPanel.VirtualizationModeProperty); }
/// <summary> /// Gets the value of the <see cref="P:DigitalRune.Window.AccessKeyScope.IsEnabled"/> /// attached property from a given <see cref="DependencyObject"/> object. /// </summary> /// <param name="obj">The object from which to read the property value.</param> /// <returns> /// The value of the <see cref="P:DigitalRune.Window.AccessKeyScope.IsEnabled"/> /// attached property. /// </returns> /// <exception cref="ArgumentNullException"> /// <paramref name="obj"/> is <see langword="null"/>. /// </exception> public static bool GetIsEnabled(DependencyObject obj) { if (obj == null) throw new ArgumentNullException(nameof(obj)); return (bool)obj.GetValue(IsEnabledProperty); }
private static void OnAttachChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { Action<System.Windows.Interactivity.TriggerBase> action = null; System.Windows.Interactivity.TriggerCollection allTriggers; if (e.NewValue != e.OldValue) { System.Windows.Interactivity.TriggerBase[] enumerable = (System.Windows.Interactivity.TriggerBase[]) d.GetValue(MessageTriggersProperty); allTriggers = Interaction.GetTriggers(d); if (enumerable != null) { if (action == null) { action = (Action<System.Windows.Interactivity.TriggerBase>) (x => allTriggers.Remove(x)); } enumerable.Apply<System.Windows.Interactivity.TriggerBase>(action); } System.Windows.Interactivity.TriggerBase[] baseArray2 = Parser.Parse(d, e.NewValue as string).ToArray<System.Windows.Interactivity.TriggerBase>(); baseArray2.Apply<System.Windows.Interactivity.TriggerBase>(new Action<System.Windows.Interactivity.TriggerBase>(allTriggers.Add)); if (baseArray2.Length > 0) { d.SetValue(MessageTriggersProperty, baseArray2); } else { d.ClearValue(MessageTriggersProperty); } } }
/// <summary> /// Gets the update source on change. /// </summary> /// <param name="obj">The object.</param> /// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns> /// <exception cref="System.ArgumentNullException">obj</exception> public static bool GetUpdateSourceOnChange (DependencyObject obj) { if (obj == null) throw new ArgumentNullException("obj"); return (bool)obj.GetValue(UpdateSourceOnChangeProperty); }
public static bool GetIsBaseMap(DependencyObject layer) { if (layer != null) return (bool)layer.GetValue(ESRI.ArcGIS.Client.WebMap.Document.IsBaseMapProperty); return default(bool); }
public static double GetWeight(DependencyObject uiElement) { if (uiElement == null) return 0; else return (double)uiElement.GetValue(TreeMapsPanel.WeightProperty); }
// Existing GetPropertyValue for the TextDecorationCollection will return the first collection, even if it is empty. // this skips empty collections so we can get the actual value. // slightly modified code from https://social.msdn.microsoft.com/Forums/vstudio/en-US/3ac626cf-60aa-427f-80e9-794f3775a70e/how-to-tell-if-richtextbox-selection-is-underlined?forum=wpf public static object GetRealPropertyValue(this swd.TextRange textRange, sw.DependencyProperty formattingProperty, out swd.TextRange fullRange) { object value = null; fullRange = null; var pointer = textRange.Start as swd.TextPointer; if (pointer != null) { var needsContinue = true; swd.TextElement text = null; sw.DependencyObject element = pointer.Parent as swd.TextElement; while (needsContinue && (element is swd.Inline || element is swd.Paragraph || element is swc.TextBlock)) { value = element.GetValue(formattingProperty); text = element as swd.TextElement; var seq = value as IEnumerable; needsContinue = (seq == null) ? value == null : seq.Cast <object>().Count() == 0; element = element is swd.TextElement ? ((swd.TextElement)element).Parent : null; } if (text != null) { fullRange = new swd.TextRange(text.ElementStart, text.ElementEnd); } } return(value); }
/// <summary> /// Gets the IList that contains the values that should be selected. /// </summary> /// <param name="element">The ListBox to check.</param> public static IList GetSelectedItemsSource(DependencyObject element) { if (element == null) throw new ArgumentNullException("element"); return (IList)element.GetValue(SelectedItemsSourceProperty); }
public static ColumnCollection GetColumnsCollection(DependencyObject d) { if (d != null) return (ColumnCollection)d.GetValue(ColumnsCollectionProperty); return null; }
/// <summary> /// Gets the value of the <strong>MultiBindings</strong> attached property from a given /// <see cref="DependencyObject"/> object. /// </summary> /// <param name="obj">The object from which to read the property value.</param> /// <return>The value of the <strong>MultiBindings</strong> attached property.</return> /// <exception cref="ArgumentNullException"> /// <paramref name="obj"/> is <see langword="null"/>. /// </exception> public static MultiBindings GetMultiBindings(DependencyObject obj) { if (obj == null) throw new ArgumentNullException("obj"); return (MultiBindings)obj.GetValue(MultiBindingsProperty); }
/// <summary> /// Used to retrieve the root, non-framework-created view. /// </summary> /// <param name="view">The view to search.</param> /// <returns>The root element that was not created by the framework.</returns> /// <remarks>In certain instances the WindowManager creates UI elements in order to display windows. /// For example, if you ask the window manager to show a UserControl as a dialog, it creates a window to host the UserControl in. /// The WindowManager marks that element as a framework-created element so that it can determine what it created vs. what was intended by the developer. /// Calling GetSignificantView allows the framework to discover what the original element was. /// </remarks> public static DependencyObject GetSignificantView(DependencyObject view) { if((bool)view.GetValue(IsElementGeneratedProperty)) return (DependencyObject)((ContentControl)view).Content; return view; }
public static Object Eval(Object container, String expression) { Binding binding = new Binding(expression) { Source = container }; DependencyObject dummyDO = new DependencyObject(); BindingOperations.SetBinding(dummyDO, DummyProperty, binding); return dummyDO.GetValue(DummyProperty); }
public static string GetSortField(DependencyObject obj) { if (obj == null) throw new ArgumentNullException("obj"); return (string)obj.GetValue(SortFieldProperty); }
public static bool GetLoadBindingsFromVM(DependencyObject obj) { if (obj == null) throw new ArgumentNullException("obj"); return (bool)obj.GetValue(LoadBindingsFromVMProperty); }
/// <summary> /// Gets the state of the current sub. /// </summary> /// <param name="obj">The object.</param> /// <returns>System.String.</returns> public static string GetCurrentSubState(DependencyObject obj) { if (obj != null) return (string)obj.GetValue(CurrentSubStateProperty); return null; }
public static bool GetGenerateColumns(DependencyObject element) { if (element == null) { throw new ArgumentNullException("element"); } return (bool)element.GetValue(GenerateColumnsProperty); }
public static SortInfo GetSortInfo(DependencyObject obj) { if (obj == null) throw new ArgumentNullException("obj"); return (SortInfo)obj.GetValue(SortInfoProperty.DependencyProperty); }
/// <summary> /// Gets the value for the <see cref="RegionNameProperty"/> attached property. /// </summary> /// <param name="regionTarget">The object to adapt. This is typically a container (i.e a control).</param> /// <returns>The name of the region that should be created when /// <see cref="RegionManagerProperty"/> is also set in this element.</returns> public static string GetRegionName(DependencyObject regionTarget) { if (regionTarget == null) throw new ArgumentNullException(nameof(regionTarget)); return regionTarget.GetValue(RegionNameProperty) as string; }
public static T GetValueThreadSafe <T>(this System.Windows.DependencyObject obj, System.Windows.DependencyProperty p) { return((T)obj.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Background, (System.Windows.Threading.DispatcherOperationCallback) delegate { return obj.GetValue(p); }, p)); }
private static void CanOpenAppFile(object sender, System.Windows.Input.CanExecuteRoutedEventArgs e) { Windows.DependencyObject d = sender as Windows.DependencyObject; AppFileManager manager = (d == null ? null : d.GetValue(Windows.FrameworkElement.DataContextProperty) as AppFileManager); AppFileInfo file = e.Parameter as AppFileInfo; e.CanExecute = file != null && manager != null && manager.IsUploading == false; }
/// <summary> /// This works like FrameworkElement.FindName only in reverse up the tree instead of down /// - http://msdn.microsoft.com/en-us/library/system.windows.frameworkelement.findname.aspx /// /// </summary> /// <param name="obj"></param> /// <returns></returns> public static object FindNameUpTree(this System.Windows.DependencyObject child, string controlToFindName) { System.Windows.DependencyObject current = child; string currentName = null; do { current = current.GetParent(); currentName = current.GetValue(System.Windows.Controls.Control.NameProperty) as string; // if it doesn't have one this should be null right??? } while ((current != null) && !string.Equals(currentName, controlToFindName)); return(current); }
private void OnRemoveAppFile(object sender, System.Windows.Input.ExecutedRoutedEventArgs e) { AppFileInfo file = e.Parameter as AppFileInfo; Windows.DependencyObject d = sender as Windows.DependencyObject; AppFileManager manager = null; while (d != null && manager == null) { manager = (d == null ? null : d.GetValue(Windows.FrameworkElement.DataContextProperty) as AppFileManager); d = System.Windows.Media.VisualTreeHelper.GetParent(d); } if (manager != null) { manager.Items.Remove(file); } }
// Existing GetPropertyValue for the TextDecorationCollection will return the first collection, even if it is empty. // this skips empty collections so we can get the actual value. // slightly modified code from https://social.msdn.microsoft.com/Forums/vstudio/en-US/3ac626cf-60aa-427f-80e9-794f3775a70e/how-to-tell-if-richtextbox-selection-is-underlined?forum=wpf object GetPropertyValue(swd.TextRange textRange, sw.DependencyProperty formattingProperty) { object value = null; var pointer = textRange.Start as swd.TextPointer; if (pointer != null) { var needsContinue = true; sw.DependencyObject element = pointer.Parent as swd.TextElement; while (needsContinue && (element is swd.Inline || element is swd.Paragraph || element is swc.TextBlock)) { value = element.GetValue(formattingProperty); var seq = value as IEnumerable; needsContinue = (seq == null) ? value == null : seq.Cast <Object>().Count() == 0; element = element is swd.TextElement ? ((swd.TextElement)element).Parent : null; } } return(value); }
/// <summary> /// Overriden base method to allow the selection of the correct DataTemplate /// </summary> /// <param name="item">The item for which the template should be retrieved</param> /// <param name="container">The object containing the current item</param> /// <returns>The <see cref="DataTemplate"/> to use when rendering the <paramref name="item"/></returns> public override System.Windows.DataTemplate SelectTemplate(object item, System.Windows.DependencyObject container) { //First, we gather all the templates associated with the current control through our dependency property Template[] templates = (Template[])container.GetValue(TemplatesProperty); //Then we go through them checking if any of them match our criteria foreach (var template in templates) { //In this case, we are checking whether the type of the item is the same as the type supported by our DataTemplate if (template.Value.IsInstanceOfType(item)) { //And if it is, then we return that DataTemplate return(template.DataTemplate); } } //If all else fails, then we go back to using the default DataTemplate return(base.SelectTemplate(item, container)); }
private void OnAddAppFile(object sender, System.Windows.Input.ExecutedRoutedEventArgs e) { OpenFileDialog dialog = new OpenFileDialog(); dialog.Title = "选择文件"; dialog.Filter = "(所有文件)|*.*"; dialog.Multiselect = true; DialogResult result = dialog.ShowDialog(); if (result == DialogResult.OK) { Windows.DependencyObject d = sender as Windows.DependencyObject; AppFileManager manager = (d == null ? null : d.GetValue(Windows.FrameworkElement.DataContextProperty) as AppFileManager); try { foreach (string name in dialog.FileNames) { AppFileInfo fileInfo = new AppFileInfo() { Version = FileHelper.GetCurrentVersion(), FileName = name, Status = FileStatus.New, Enterprise = manager.SelectedEnterprise }; int index = manager.Items.IndexOf(fileInfo); if (index > -1) { AppFileInfo current = manager.Items[index] as AppFileInfo; current.FileName = name; continue; } manager.Items.Add(fileInfo); } } catch (Exception ex) { MessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
/// <summary> /// Manually searches up the parent tree to find the first FrameworkElement that /// has a non-null background, and returns that Brush. /// If no parent is found with a brush, then this returns WindowBrush. /// </summary> /// <param name="dependencyObject"></param> /// <returns></returns> private static SWM.Brush FindBackgroundParent(SW.DependencyObject dependencyObject) { if (dependencyObject == null) { return(defaultBrush); } Brush backgroundBrush = null; backgroundBrush = (Brush)dependencyObject.GetValue(SWC.Control.BackgroundProperty); if (backgroundBrush == null) { SW.FrameworkElement frameworkElement = dependencyObject as SW.FrameworkElement; if (frameworkElement != null) { DependencyObject parentElement = VisualTreeHelper.GetParent(frameworkElement); backgroundBrush = FindBackgroundParent(parentElement); } } return(backgroundBrush ?? defaultBrush); }
public override void OnValueUpdating(System.Windows.DependencyObject sender, object baseValue) { FrameworkElement element; if (!(sender is FrameworkElement)) { return; } element = (FrameworkElement)sender; if (sender.GetValue(ValueProperty) == baseValue && !FirstLoad) { return; } if (FirstLoad) { RoutedEventHandler OnLoad = null; OnLoad = (ss, ee) => { element.Loaded -= OnLoad; DoAnimation(element, (bool)baseValue); FirstLoad = false; }; element.Loaded += OnLoad; } else { DoAnimation(element, (bool)baseValue); } }
public static object GetSelectedItem(System.Windows.DependencyObject obj) { return((object)obj.GetValue(SelectedItemProperty)); }
public static bool IsControlEditInitialized(sw.DependencyObject obj) => (bool)obj.GetValue(CellProperties.ControlEditInitializedProperty);
/// <summary> /// Returns the value of the AutoScrollToCurrentItemProperty /// </summary> /// <param name="obj">The dependency-object whichs value should be returned</param> /// <returns>The value of the given property</returns> public static bool GetAutoScrollToCurrentItem(System.Windows.DependencyObject obj) { return((bool)obj.GetValue(AutoScrollToCurrentItemProperty)); }
public static string GetId(Windows.DependencyObject target) => (string)target.GetValue(IdProperty);
public static object GetReportSource(System.Windows.DependencyObject target) { return(target.GetValue(ReportSourceProperty)); }
/// <summary> /// Gets the ribbon property /// </summary> /// <param name="obj">Specifies the dependency object.</param> /// <returns></returns> public static Ribbon GetRibbon(System.Windows.DependencyObject obj) { return((Ribbon)obj.GetValue(RibbonProperty)); }
public static Point GetCanvasPos(this System.Windows.DependencyObject obj) { return(new Point((double)obj.GetValue(Canvas.LeftProperty), (double)obj.GetValue(Canvas.TopProperty))); }