/// <summary> /// 让设计器加载指定的文档对象 /// </summary> /// <param name="designer"></param> /// <param name="document"></param> public static void BindDocument(this ModelingDesigner designer, ODMLDocument document) { DocumentBinder.BindDocument(designer, document); //绑定新的文档时,需要清空文件路径。 designer.ClearValue(CurrentOdmlFileProperty); }
/// <summary> /// Removes the data context changed handler. /// </summary> /// <param name="element">The element from which the handler has to be removed</param> /// <param name="handler">The handler to remove</param> public static void RemoveDataContextChangedHandler(this FrameworkElement element, EventHandler handler) { if (element == null || handler == null) { return; } EventHandler currentHandler = (EventHandler)element.GetValue(DataContextChangedHandlerProperty); currentHandler -= handler; if (currentHandler == null) { element.ClearValue(DataContextChangedHandlerProperty); element.ClearValue(InheritedDataContextProperty); } else { element.SetValue(DataContextChangedHandlerProperty, currentHandler); } }
public static void Apply(this FrameworkElement element, Style style) { if (style == null) { return; } foreach (Setter setter in style.Setters) { element.ClearValue(setter.Property); } element.Style = style; }
/// <summary>${utility_DoubleClickHelper_method_RemoveDoubleClick_D}</summary> /// <param name="element">The element.</param> /// <param name="handler">The handler.</param> public static void RemoveDoubleClick(this UIElement element, MouseButtonEventHandler handler) { if (element != null) { element.MouseLeftButtonDown -= element_MouseLeftButtonDown; List<MouseButtonEventHandler> handlers = element.GetValue(DoubleClickHandlersProperty) as List<MouseButtonEventHandler>; if (handlers != null) { handlers.Remove(handler); if (handlers.Count == 0) element.ClearValue(DoubleClickHandlersProperty); } } }
/// <summary> /// Clears the local value of the read only property. /// </summary> /// <param name="element">The element to clear the value to.</param> /// <param name="key">The key for the dependency property to be cleared.</param> public static void ClearValue(this DependencyObject element, DependencyPropertyKey key) { if (key == null) return; try { readonlyDPThatCanBeChanged.Add(key.DependencyProperty); if (element != null) element.ClearValue(key.DependencyProperty); } finally { readonlyDPThatCanBeChanged.Remove(key.DependencyProperty); } }
public static void SetTextTrimming(this HtmlStyleDictionary style, TextTrimming textTrimming) { if (textTrimming == TextTrimming.None) { style.ClearValue("text-overflow"); } else { style.SetValue("text-overflow", "ellipsis"); } }
public static void SetSize(this HtmlStyleDictionary style, Size size, IHtmlValueConverter converter) { if (size.Width.IsNaN()) { style.ClearValue("width"); } else { style.SetValue("width", converter.ToPixelString(size.Width)); } if (size.Height.IsNaN()) { style.ClearValue("height"); } else { style.SetValue("height", converter.ToPixelString(size.Height)); } }
public static void SetOpacity(this HtmlStyleDictionary style, double opacity, IHtmlValueConverter converter) { if (opacity == 1.0) { style.ClearValue("opacity"); } else { style.SetValue("opacity", converter.ToImplicitValueString(opacity)); } }
public static void SetIsVisible(this HtmlStyleDictionary style, bool isVisible) { if (isVisible) { style.ClearValue("display"); } else { style.SetValue("display", "none"); } }
public static void SetBackgroundLocation(this HtmlStyleDictionary style, Point location, IHtmlValueConverter converter) { if (Point.IsNullOrEmpty(location)) { style.ClearValue("background-position"); } else { style.SetValue("background-position", converter.ToPixelString(location)); } }
public static void SetBackground(this HtmlStyleDictionary style, Brush background, IHtmlValueConverter converter) { style.ClearValue("background-color"); style.ClearValue("background-image"); if (background is SolidColorBrush) { style.SetValue("background-color", converter.ToColorString((SolidColorBrush)background)); } else if (background != null) { style.SetValue("background-image", converter.ToImageString(background)); } }
public static void SetFontSize(this HtmlStyleDictionary style, double fontSize, IHtmlValueConverter converter) { if (fontSize.IsNaN()) { style.ClearValue("font-size"); } else { style.SetValue("font-size", converter.ToPixelString(fontSize)); } }
public static void SetFontStretch(this HtmlStyleDictionary style, FontStretch fontStretch, IHtmlValueConverter converter) { if (fontStretch == FontStretch.Normal) { style.ClearValue("font-stretch"); } else { style.SetValue("font-stretch", converter.ToFontStretchString(fontStretch)); } }
public static void SetCornerRadius(this HtmlStyleDictionary style, CornerRadius cornerRadius, IHtmlValueConverter converter) { style.ClearValue("border-radius"); style.ClearValue("border-top-left-radius"); style.ClearValue("border-top-right-radius"); style.ClearValue("border-bottom-left-radius"); style.ClearValue("border-bottom-right-radius"); if (cornerRadius != CornerRadius.Zero) { if (cornerRadius.IsUniform) { style.SetValue("border-radius", converter.ToPixelString(cornerRadius.TopLeft)); } else { style.SetValue("border-top-left-radius", converter.ToPixelString(cornerRadius.TopLeft)); style.SetValue("border-top-right-radius", converter.ToPixelString(cornerRadius.TopRight)); style.SetValue("border-bottom-left-radius", converter.ToPixelString(cornerRadius.BottomLeft)); style.SetValue("border-bottom-right-radius", converter.ToPixelString(cornerRadius.BottomRight)); } } }
public static void SetFontFamily(this HtmlStyleDictionary style, FontFamily fontFamily, IHtmlValueConverter converter) { if (!fontFamily.FamilyNames.Any()) { style.ClearValue("font-family"); } else { style.SetValue("font-family", converter.ToFontFamilyNamesString(fontFamily)); } }
public static void SetBorderThickness(this HtmlStyleDictionary style, Thickness borderThickness, IHtmlValueConverter converter) { if (borderThickness == Thickness.Zero) { style.ClearValue("border-style"); style.ClearValue("border-width"); style.ClearValue("border-image-slice"); } else { style.SetValue("border-style", "solid"); style.SetValue("border-width", converter.ToPixelString(borderThickness)); style.SetValue("border-image-slice", converter.ToImplicitValueString(borderThickness)); } }
public static void SetBorderBrush(this HtmlStyleDictionary style, Brush borderBrush, IHtmlValueConverter converter) { style.ClearValue("border-color"); style.ClearValue("border-image-source"); if (borderBrush is SolidColorBrush) { style.SetValue("border-color", converter.ToColorString((SolidColorBrush)borderBrush)); } else if (borderBrush != null) { style.SetValue("border-image-source", converter.ToImageString(borderBrush)); } }
public static void SetBackgroundSize(this HtmlStyleDictionary style, Size size, IHtmlValueConverter converter) { if (Size.IsNullOrEmpty(size)) { style.ClearValue("background-size"); } else { style.SetValue("background-size", converter.ToPixelString(size)); } }
public static void SetTransform(this HtmlStyleDictionary style, Transform transform, IHtmlValueConverter converter) { if (transform == Transform.Identity) { style.ClearValue("transform"); } else { style.SetValue("transform", transform.Value.ToString()); } }
/// <summary> /// Clears the content control after using in an ItemsControl. /// </summary> /// <param name="this">The this.</param> /// <param name="item">The item.</param> public static void ClearContentControl( this ContentControl @this, object item) { if (item != @this) { @this.ClearValue(ContentControl.ContentProperty); } }
/// <summary> /// Remove a handler from a DependencyProperty /// </summary> /// <param name="source">The DependencyObject instance on which we want to monitor the property</param> /// <param name="name">The PropertyPath to the property we want to monitor</param> /// <param name="handler">The handler to invoke when the property changed</param> public static void RemoveChangedHandler(this DependencyObject source, string name, DependencyPropertyChangedEventHandler handler) { var subscribers = GetListeners(source); var subscriber = subscribers.FirstOrDefault(s => s.Handler == handler && s.PropertyPath == name); if (subscriber != null) { subscriber.Dispose(); subscribers.Remove(subscriber); } if (subscribers.Count == 0) source.ClearValue(ListenersProperty); }
/// <summary> /// Removes the data context changed handler. /// </summary> /// <param name="element">The element from which the handler has to be removed.</param> /// <param name="handler">The handler to remove.</param> /// <exception cref="ArgumentNullException">The <paramref name="element"/> is <c>null</c>.</exception> /// <exception cref="ArgumentNullException">The <paramref name="handler"/> is <c>null</c>.</exception> public static void RemoveDataContextChangedHandler(this FrameworkElement element, DependencyPropertyChangedEventHandler handler) { Argument.IsNotNull("element", element); Argument.IsNotNull("handler", handler); var currentHandler = (DependencyPropertyChangedEventHandler)element.GetValue(DataContextChangedHandlerProperty); currentHandler -= handler; if (currentHandler == null) { element.ClearValue(DataContextChangedHandlerProperty); element.ClearValue(InheritedDataContextProperty); } else { element.SetValue(DataContextChangedHandlerProperty, currentHandler); } }
public static void ClearDataContext(this Control control) { control.ClearValue(DataContextProperty); }
public static void SetForeground(this HtmlStyleDictionary style, Brush foreground, IHtmlValueConverter converter) { if (foreground == null) { style.ClearValue("color"); } else if (foreground is SolidColorBrush) { style.SetValue("color", converter.ToColorString((SolidColorBrush)foreground)); } else { throw new Granular.Exception("A \"{0}\" foreground brush is not supported", foreground.GetType()); } }
public static void SetFontStyle(this HtmlStyleDictionary style, FontStyle fontStyle, IHtmlValueConverter converter) { if (fontStyle == FontStyle.Normal) { style.ClearValue("font-style"); } else { style.SetValue("font-style", converter.ToFontStyleString(fontStyle)); } }
public static void SetBackgroundImage(this HtmlStyleDictionary style, ImageSource imageSource, IHtmlValueConverter converter) { if (imageSource == null) { style.ClearValue("background-image"); } else { style.SetValue("background-image", converter.ToUrlString(((RenderImageSource)imageSource.RenderImageSource).Url)); } }
public static void SetFontWeight(this HtmlStyleDictionary style, FontWeight fontWeight, IHtmlValueConverter converter) { if (fontWeight == FontWeight.Normal) { style.ClearValue("font-weight"); } else { style.SetValue("font-weight", converter.ToFontWeightString(fontWeight)); } }
public static Task OpenAsync(this MediaElement media, Uri uri, CancellationToken cancel) { TaskCompletionSource<object> tcs = new TaskCompletionSource<object>(); if (cancel.IsCancellationRequested) { tcs.SetCanceled(); return tcs.Task; } if (media.CurrentState == MediaElementState.Buffering || media.CurrentState == MediaElementState.Opening || media.CurrentState == MediaElementState.Playing) { tcs.SetException(new Exception("MediaElement not ready to open")); return tcs.Task; } RoutedEventHandler lambdaOpened = null; RoutedEventHandler lambdaChanged = null; ExceptionRoutedEventHandler lambdaFailed = null; CancellationTokenRegistration? cancelReg = null; Action removeLambdas = () => { media.MediaOpened -= lambdaOpened; media.MediaFailed -= lambdaFailed; media.CurrentStateChanged -= lambdaChanged; if (cancelReg.HasValue) cancelReg.Value.Dispose(); //removeLambdas = () => return; // in case two lambdas get fired one after the other }; lambdaOpened = (x,y) => { removeLambdas(); tcs.TrySetResult(null); }; lambdaFailed = (s, e) => { removeLambdas(); tcs.TrySetException(new Exception(e.ErrorMessage)); }; lambdaChanged = (x,y) => { if (media.CurrentState != MediaElementState.Closed) return; removeLambdas(); tcs.TrySetCanceled(); }; media.MediaOpened += lambdaOpened; media.MediaFailed += lambdaFailed; media.CurrentStateChanged += lambdaChanged; media.Source = uri; if (!tcs.Task.IsCompleted) { // The above condition guards against lambas being invoked by Source assignment cancelReg = cancel.Register(() => { dynamic dummy = media.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { media.ClearValue(MediaElement.SourceProperty); }); }); } return tcs.Task; }