private static void ProgressPropertyChangedCallback(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs e) { var isLoading = (bool)dependencyObject.GetValue(IsInProgressProperty); var isError = (bool)dependencyObject.GetValue(IsErrorProperty); dependencyObject.SetValue(IsStatusVisibleProperty, isError || isLoading); var canTryAgain = (bool) dependencyObject.GetValue(CanTryAgainProperty); dependencyObject.SetValue(IsTryAgainButtonVisibleProperty, isError && canTryAgain); }
public static bool GetEnabled(DependencyObject sender) { if (sender == null) { return false; } return (bool)sender.GetValue(EnabledProperty); }
/// <summary> /// Gets the <see cref="BehaviorCollection"/> associated with a specified object. /// </summary> /// <param name="obj">The <see cref="Windows.UI.Xaml.DependencyObject"/> from which to retrieve the <see cref="BehaviorCollection"/>.</param> /// <returns>A <see cref="BehaviorCollection"/> containing the behaviors associated with the specified object.</returns> public static BehaviorCollection GetBehaviors(DependencyObject obj) { if (obj == null) { throw new ArgumentNullException("obj"); } BehaviorCollection behaviorCollection = (BehaviorCollection)obj.GetValue(Interaction.BehaviorsProperty); if (behaviorCollection == null) { behaviorCollection = new BehaviorCollection(); obj.SetValue(Interaction.BehaviorsProperty, behaviorCollection); var frameworkElement = obj as FrameworkElement; if (frameworkElement != null) { frameworkElement.Loaded -= FrameworkElement_Loaded; frameworkElement.Loaded += FrameworkElement_Loaded; frameworkElement.Unloaded -= FrameworkElement_Unloaded; frameworkElement.Unloaded += FrameworkElement_Unloaded; } } return behaviorCollection; }
public static Action<object> GetAction(DependencyObject sender) { if (sender == null) { return null; } return (Action<object>)sender.GetValue(ActionProperty); }
public static string GetSearchText(DependencyObject sender) { if (sender == null) { return null; } return (string)sender.GetValue(SearchTextProperty); }
public static string GetVisualState(DependencyObject sender) { if (sender == null) { return null; } return (string)sender.GetValue(GoToStateProperty); }
public static ReadOnlyCollection<string> GetPropertyErrors(DependencyObject sender) { if (sender == null) { return null; } return (ReadOnlyCollection<string>)sender.GetValue(PropertyErrorsProperty); }
public static string GetTitle(DependencyObject obj) { if (obj == null) throw new ArgumentNullException(nameof(obj)); return (string)obj.GetValue(TitleProperty); }
private static async void OnCacheUriChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { //Uri oldCacheUri = (Uri)e.OldValue; Uri newCacheUri = (Uri)d.GetValue(CacheUriProperty); var image = (Image)d; if (newCacheUri != null) { try { //Get image from cache (download and set in cache if needed) var cacheUri = await WebDataCache.GetLocalUriAsync(newCacheUri); //Set cache uri as source for the image image.Source = new BitmapImage(cacheUri); } catch (Exception ex) { Debug.WriteLine(ex); //Revert to using passed URI image.Source = new BitmapImage(newCacheUri); } } else image.Source = null; }
public static ImageSource GetIconSource(DependencyObject obj) { if (obj == null) throw new ArgumentNullException(nameof(obj)); return (ImageSource)obj.GetValue(IconSourceProperty); }
public static Brush GetHeaderForeground(DependencyObject obj) { if (obj == null) throw new ArgumentNullException(nameof(obj)); return (Brush)obj.GetValue(HeaderForegroundProperty); }
/// <summary> /// Gets the value of the AutoWireViewModel attached property. /// </summary> /// <param name="obj">The dependency object that has this attached property.</param> /// <returns><c>True</c> if view model autowiring is enabled; otherwise, <c>false</c>.</returns> public static bool GetAutoWireViewModel(DependencyObject obj) { if (obj != null) return (bool)obj.GetValue(AutoWireViewModelProperty); return false; }
/// <summary> /// Handles changes to the Cursor property. /// </summary> /// <param name="d"> /// The <see cref="DependencyObject"/> on which /// the property has changed value. /// </param> /// <param name="e"> /// Event data that is issued by any event that /// tracks changes to the effective value of this property. /// </param> private static void OnCursorChanged( DependencyObject d, DependencyPropertyChangedEventArgs e) { CoreCursor oldCursor = (CoreCursor)e.OldValue; CoreCursor newCursor = (CoreCursor)d.GetValue(CursorProperty); if (oldCursor == null) { var handler = new CursorDisplayHandler(); handler.Attach((Control)d); SetCursorDisplayHandler(d, handler); } else { var handler = GetCursorDisplayHandler(d); if (newCursor == null) { handler.Detach(); SetCursorDisplayHandler(d, null); } else { handler.UpdateCursor(); } } }
/// <summary> /// Handles changes to the BottomAppBar property. /// </summary> /// <param name="d"> /// The <see cref="DependencyObject"/> on which /// the property has changed value. /// </param> /// <param name="e"> /// Event data that is issued by any event that /// tracks changes to the effective value of this property. /// </param> private static async void OnBottomAppBarChanged( DependencyObject d, DependencyPropertyChangedEventArgs e) { var oldBottomAppBar = (AppBar)e.OldValue; var newBottomAppBar = (AppBar)d.GetValue(BottomAppBarProperty); if (DesignMode.DesignModeEnabled) { return; } var fe = (FrameworkElement)d; var parentPage = fe.GetFirstAncestorOfType<Page>(); if (parentPage == null) { await fe.WaitForLoadedAsync(); parentPage = fe.GetFirstAncestorOfType<Page>(); if (parentPage == null) { throw new InvalidOperationException("PageExtensions.BottomAppBar is used to set the BottomAppBar on a parent page control and so it needs to be used in a control that is hosted in a Page."); } } parentPage.BottomAppBar = newBottomAppBar; }
public static Brush GetHighlightBrush(DependencyObject sender) { if (sender == null) { return null; } return (Brush)sender.GetValue(HighlightBrushProperty); }
public static string GetWatermark(DependencyObject obj) { if (obj == null) throw new ArgumentNullException("obj", "obj can not be null"); return (string) obj.GetValue(WatermarkProperty); }
public static Action<KeyRoutedEventArgs> GetKeyDownAction(DependencyObject obj) { if (obj == null) return null; return (Action<KeyRoutedEventArgs>)obj.GetValue(KeyDownActionProperty); }
/// <summary> /// Handles changes to the InheritedDataContext DependencyProperty. /// </summary> /// <param name="d">Instance with property change.</param> /// <param name="e">Property change details.</param> private static void OnInheritedDataContextChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { EventHandler handler = d.GetValue(DataContextChangedHandlerProperty) as EventHandler; if (handler!=null) { handler(d,EventArgs.Empty); } }
public static UIElement GetPaneHeader(DependencyObject obj) { if (obj == null) { throw new ArgumentNullException("obj"); } return (UIElement)obj.GetValue(PaneHeaderProperty); }
private static void OnSourceHtmlChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { string newHtmlString = (string)d.GetValue(SourceHtmlProperty); var webView = (WebView)d; webView.NavigateToString(newHtmlString); }
/// <summary> /// Handles changes to the Format property. /// </summary> /// <param name="d"> /// The <see cref="DependencyObject"/> on which /// the property has changed value. /// </param> /// <param name="e"> /// Event data that is issued by any event that /// tracks changes to the effective value of this property. /// </param> private static void OnFormatChanged( DependencyObject d, DependencyPropertyChangedEventArgs e) { ValidTextBoxFormats oldFormat = (ValidTextBoxFormats)e.OldValue; ValidTextBoxFormats newFormat = (ValidTextBoxFormats)d.GetValue(FormatProperty); SetupAndValidate((TextBox)d); }
/// <summary> /// Gets the ClearChildViews attached property from a DependencyObject. /// </summary> /// <param name="target">The object from which to get the value.</param> /// <returns>The value of the ClearChildViews attached property in the target specified.</returns> public static bool GetClearChildViews(DependencyObject target) { if (target == null) { throw new ArgumentNullException("target"); } return (bool) target.GetValue(ClearChildViewsProperty); }
public static CommandBar GetCommandBar(DependencyObject obj) { if(obj == null) { throw new ArgumentNullException("obj"); } return (CommandBar)obj.GetValue(CommandBarProperty); }
/// <summary> /// Gets the value of the MenuFlyout property of the specified object. /// </summary> /// <param name="element">Object to query concerning the MenuFlyout property.</param> /// <returns>Value of the MenuFlyout property.</returns> public static MenuFlyout GetMenuFlyout( DependencyObject element ) { if ( element == null ) { throw new ArgumentNullException( "element" ); } return (MenuFlyout)element.GetValue( MenuFlyoutProperty ); }
void HeaderChanged(DependencyObject sender, DependencyProperty prop) { string header = (string)sender.GetValue(prop); //Double check to make sure that we don't needlessly realize the header presenter if (!string.IsNullOrEmpty(Header) && _header == null) { _header = (ContentPresenter)GetTemplateChild("HeaderPresenter"); //This will realize the element } }
public static string GetMethodName(DependencyObject attached) { if (attached == null) { throw new ArgumentNullException("attached"); } return (string)attached.GetValue(MethodNameProperty); }
/// <summary> /// Handles changes to the FadeTransitioningContentTemplate property. /// </summary> /// <param name="d"> /// The <see cref="DependencyObject"/> on which /// the property has changed value. /// </param> /// <param name="e"> /// Event data that is issued by any event that /// tracks changes to the effective value of this property. /// </param> private static async void OnFadeTransitioningContentTemplateChanged( DependencyObject d, DependencyPropertyChangedEventArgs e) { DataTemplate oldFadeTransitioningContentTemplate = (DataTemplate)e.OldValue; DataTemplate newFadeTransitioningContentTemplate = (DataTemplate)d.GetValue(FadeTransitioningContentTemplateProperty); await d.FadeOut(); ((ContentControl)d).ContentTemplate = newFadeTransitioningContentTemplate; await d.FadeIn(); }
public static BehaviorCollection GetBehaviors(DependencyObject obj) { BehaviorCollection behaviors = (BehaviorCollection)obj.GetValue(BehaviorsProperty); if (behaviors == null) { behaviors = new BehaviorCollection(); obj.SetValue(BehaviorsProperty, behaviors); } return behaviors; }
/// <summary> /// Gets the TriggerCollection containing the triggers associated with the specified object. /// /// </summary> /// <param name="obj">The object from which to retrieve the triggers.</param> /// <returns> /// A TriggerCollection containing the triggers associated with the specified object. /// </returns> public static TriggerCollection GetTriggers(DependencyObject obj) { TriggerCollection triggerCollection = (TriggerCollection)obj.GetValue(Interaction.TriggersProperty); if (triggerCollection == null) { triggerCollection = new TriggerCollection(); obj.SetValue(Interaction.TriggersProperty, triggerCollection); } return triggerCollection; }
/// <summary> /// Handles changes to the PlainText property. /// </summary> /// <param name="d"> /// The <see cref="DependencyObject"/> on which /// the property has changed value. /// </param> /// <param name="e"> /// Event data that is issued by any event that /// tracks changes to the effective value of this property. /// </param> private static void OnPlainTextChanged( DependencyObject d, DependencyPropertyChangedEventArgs e) { string oldPlainText = (string)e.OldValue; string newPlainText = (string)d.GetValue(PlainTextProperty); ((RichTextBlock)d).Blocks.Clear(); var paragraph = new Paragraph(); paragraph.Inlines.Add(new Run { Text = newPlainText }); ((RichTextBlock)d).Blocks.Add(paragraph); }