XamlHelper

Ecng.Xaml

Miscellaneous WPF helper and extension methods for UI threading, bindings, imaging, dialogs, and type conversions.

Свойства

CurrentThreadDispatcher : Dispatcher

Gets the Dispatcher associated with the current thread.

Методы

CopyToClipboard``1(T)

Copies the provided value to the system clipboard on the UI thread.

DeleteHideable(Window)

Removes previously added hide-on-close behavior.

EnsureUIThread(object)

Ensures the current thread is the UI thread and throws otherwise.

obj
Any DispatcherObject or Dispatcher or other object to infer dispatcher from.
EnsureUIThread()

Throws if the current thread is not the UI thread.

FindLogicalChild``1(DependencyObject)

Searches the logical tree depth-first and returns the first child of the specified type, or null if none found.

FindLogicalParentOfType``1(DependencyObject)

Walks up the logical tree and returns the first parent of the specified type, or null if none found.

FindVisualChilds``1(DependencyObject)

Enumerates all visual children of the specified type.

FindVisualChild``1(DependencyObject)

Returns the first visual child of the specified type, or null if none found.

FromWpf(VerticalAlignment) : VerticalAlignment

Convert VerticalAlignment value to VerticalAlignment.

value
VerticalAlignment value.

Возвращает: VerticalAlignment value.

FromWpf(Point) : VerticalAlignment

Convert Point value to PointF.

value
Point value.

Возвращает: PointF value.

FromWpf(Brush) : VerticalAlignment

Convert Brush value to DrawingBrush.

value
Brush value.

Возвращает: DrawingBrush value.

FromWpf(Color) : VerticalAlignment

Convert Color value to Color.

value
Color value.

Возвращает: Color value.

FromWpf(HorizontalAlignment) : VerticalAlignment

Convert HorizontalAlignment value to HorizontalAlignment.

value
HorizontalAlignment value.

Возвращает: HorizontalAlignment value.

FromWpf(Thickness) : VerticalAlignment

Convert Thickness value to Thickness.

value
Thickness value.

Возвращает: Thickness value.

GetActiveOrMainWindow(Application) : Window

Returns the active window or the main window if none is active.

GetActiveWindow(Application) : Window

Returns the first active window, or null if none found.

GetActiveWindows(Application) : IEnumerable<Window>

Returns all currently active windows in the application.

GetActualSize(FrameworkElement) : ValueTuple<int, int>

Returns the element ActualWidth/ActualHeight as integers tuple.

GetBrush(DrawingImage) : Brush

Gets the first brush found in the DrawingImage's Drawing.

GetDialogResult(DependencyObject) : bool?

Boilerplate attached property "bool? DialogResult" used to set Window.DialogResult from a Button.

GetImage(FrameworkElement) : BitmapSource

Renders a FrameworkElement into a bitmap using its current size.

GetImage(Visual, ValueTuple<int, int>) : BitmapSource

Renders a Visual into a bitmap using the specified width and height.

GetImage(Visual, int, int) : ImageSource

Renders a Visual into a bitmap with the given width and height.

GetImage(string, SolidColorBrush, SolidColorBrush) : ImageSource

Gets a themed SVG/Vector icon recolored with the specified fill and stroke brushes.

GetSystemFontFamilies() : IEnumerable<string>

Get system font families.

Возвращает: System font families.

GetWindow(DependencyObject) : Window

Gets the owning window for the specified object.

GuiAsync(Dispatcher, Action, DispatcherPriority)

Executes the action on the UI thread asynchronously with the specified priority.

GuiAsync(Dispatcher, Action)

Executes the action on the UI thread asynchronously with normal priority.

GuiAsync(DispatcherObject, Action)

Executes the action on the UI thread asynchronously using the object's Dispatcher.

GuiSync(Dispatcher, Action, DispatcherPriority) : T

Executes the action synchronously on the Dispatcher with the specified priority.

GuiSync(DispatcherObject, Action) : T

Executes the action synchronously on the object's Dispatcher.

GuiSync(Dispatcher, Action) : T

Executes the action synchronously on the Dispatcher with normal priority.

GuiSync``1(Dispatcher, Func<T>)

Executes the function synchronously on the Dispatcher with normal priority and returns the result.

GuiSync``1(DispatcherObject, Func<T>)

Executes the function synchronously on the object's Dispatcher and returns its result.

GuiSync``1(Dispatcher, Func<T>, DispatcherPriority)

Executes the function synchronously on the Dispatcher with the specified priority and returns the result.

GuiThreadGetAsync(Action<CancellationToken>, CancellationToken) : Task

Invokes the provided action on the UI thread if required.

GuiThreadGetAsync(Func<CancellationToken, Task>, CancellationToken) : Task

Invokes the provided async action on the UI thread if required.

GuiThreadGetAsync``1(Func<CancellationToken, T>, CancellationToken)

Invokes the provided function on the UI thread if required and returns its result.

GuiThreadGetAsync``1(Func<CancellationToken, Task<T>>, CancellationToken)

Invokes the provided async function on the UI thread if required and returns its result.

InvokeAsync(DependencyObject, Action, DispatcherPriority, CancellationToken) : DispatcherOperation<T>

Invokes the provided function on the UI thread if required.

obj
The dependency object to get the Dispatcher from.
action
The function to invoke.
priority
DispatcherPriority
cancellationToken
CancellationToken

Возвращает: DispatcherOperation

InvokeAsync``1(DependencyObject, Func<T>, DispatcherPriority, CancellationToken)

Invokes the provided function on the UI thread if required and returns its result.

obj
The dependency object to get the Dispatcher from.
action
The function to invoke.
priority
DispatcherPriority
cancellationToken
CancellationToken

Возвращает: DispatcherOperation

IsDesignMode(DependencyObject) : bool

Returns true if running in design mode.

IsFontSupported(string) : bool

Determines if font is supported.

familyName
Font family name.

Возвращает: True if supported; otherwise false.

IsUI() : bool

Determines the current thread is associated with Dispatcher.

Возвращает: Check result.

LoadViewFromUri(Control, string)

Loads a XAML view from the specified relative pack URI into the control.

MakeHideable(Window)

Hooks Closing event to hide the window instead of closing it.

ReColor(SvgImage, Color?, Color?) : SvgImage

Change SVG image stroke/fill colors. Original is not changed.

SaveImage(BitmapSource, Stream)

Saves the bitmap into the provided stream in PNG format.

SetBindings(DependencyObject, DependencyProperty, object, string, BindingMode, IValueConverter, object)

Applies a simple single binding to the specified dependency property.

SetBindings(DependencyObject, DependencyProperty, object, PropertyPath, BindingMode, IValueConverter, object)

Applies a simple single binding to the specified dependency property with a PropertyPath.

SetDialogResult(DependencyObject, bool?)

Sets the attached DialogResult value for a button.

SetMultiBinding(DependencyObject, DependencyProperty, IMultiValueConverter, Binding[])

Creates a MultiBinding with provided bindings and converter and applies it to the specified property.

ShowModal(CommonDialog, Window) : bool

Shows the CommonDialog as modal with the specified owner window.

ShowModal(CommonDialog, DependencyObject) : bool

Shows the CommonDialog as modal using the owning object to resolve the owner window.

ShowModal(Window, Window) : bool

Shows the window as modal with the specified owner.

ShowModal(Window, DependencyObject) : bool

Shows the window as modal using the owning object to resolve the owner window.

ShowModal(Window) : bool

Shows the window as modal using Application.Current.MainWindow as owner if available.

ShowModel``1(object, DependencyObject)

Creates and shows a modal Window of type TWindow with DataContext set to the provided model.

ToBitmapImage(Stream, BitmapCreateOptions, BitmapCacheOption, bool) : BitmapImage

Creates a BitmapImage from a stream with optional init parameters.

ToColor(int) : Color

Converts ARGB int to Color.

ToInt(Color) : int

Converts a Color to ARGB int.

ToSvg(Stream) : ImageSource

Convert stream to SVG image.

stream
Stream

Возвращает: SVG image.

ToTransparent(Color, byte) : Color

Returns a copy of the color with the specified alpha channel.

ToWpf(VerticalAlignment) : VerticalAlignment

Convert VerticalAlignment value to VerticalAlignment.

value
VerticalAlignment value.

Возвращает: VerticalAlignment value.

ToWpf(HorizontalAlignment) : VerticalAlignment

Convert HorizontalAlignment value to HorizontalAlignment.

value
HorizontalAlignment value.

Возвращает: HorizontalAlignment value.

ToWpf(Thickness) : VerticalAlignment

Convert Thickness value to Thickness.

value
Thickness value.

Возвращает: Thickness value.

ToWpf(PointF) : VerticalAlignment

Convert PointF value to Point.

value
PointF value.

Возвращает: Point value.

ToWpf(Brush) : VerticalAlignment

Convert DrawingBrush value to Brush.

value
DrawingBrush value.

Возвращает: Brush value.

ToWpf(Color) : VerticalAlignment

Convert Color value to Color.

value
Color value.

Возвращает: Color value.

TryOpenWithInitialDir(DXFileDialog, DependencyObject, string) : bool

Opens a file dialog using last used directory (if available) and stores the selected directory on close.

TryOpenWithInitialDir(DXFolderBrowserDialog, DependencyObject, string) : bool

Opens a folder browser dialog using last used directory (if available) and stores the selected directory on close.

UpdateBrush(DrawingImage, Brush)

Updates all brushes inside the drawing image to the specified brush.

UpdatePen(DrawingImage, Pen)

Updates all pens inside the drawing image to the specified pen.

Url2Img(Uri) : ImageSource

Creates an ImageSource from a pack or http(s) URI. Supports SVG via DevExpress.

WpfCast``1(object)

Cast value to specified type.

value
Source value.

Возвращает: Casted value.

Поля

DialogResultProperty : DependencyProperty

Attached property that wires up a Button to set its owning window DialogResult when clicked.

DisabledCommand : ICommand

Disabled command returning false from CanExecute and throwing when executed.