Skip to main content

ElementRef

Struct ElementRef 

Source
pub struct ElementRef<T> { /* private fields */ }
Expand description

A stable typed reference to a published native element.

Components normally store references as fields. A reference is unbound before its element is published and after removal, shutdown, or window close. Imperative methods only enqueue work; they do not expose or invoke the native WinUI object.

An accepted one-shot request completes exactly once. If its binding is retired before native processing, its completion receives the typed Unavailable error.

References are control-specific:

use windows_reactor::{Button, ElementRef, TextBox};

let button = ElementRef::<Button>::new();
let _ = TextBox::new().element_ref(&button);
use windows_reactor::ElementRef;

let _ = ElementRef::<u32>::new();

Implementations§

Source§

impl<T: ReferenceControl> ElementRef<T>

Source

pub fn new() -> Self

Source§

impl<T: FocusControl> ElementRef<T>

Source

pub fn request_focus(&self) -> bool

Enqueues programmatic focus for the currently published element.

true means the request was accepted into the host queue. WinUI may later complete the request with false when focus does not move; that is not a host error.

Source

pub fn request_focus_result( &self, completion: impl Fn(Result<bool, FocusError>) + 'static, ) -> bool

Enqueues programmatic focus and reports the native result asynchronously.

Source§

impl ElementRef<WebView2>

Source

pub fn request_core_web_view2( &self, completion: impl Fn(Result<IUnknown, WebView2Error>) + 'static, ) -> bool

Requests creation of the CoreWebView2 object for the currently published control.

The returned COM object is the application-facing WebView2 core, not the XAML control owned by Reactor.

Source§

impl ElementRef<SwapChainPanel>

Source

pub fn request_set_swap_chain( &self, swap_chain: IUnknown, completion: impl Fn(Result<(), SwapChainPanelError>) + 'static, ) -> bool

Attaches an application-owned DXGI swap chain to the published panel.

Source

pub fn request_clear_swap_chain( &self, completion: impl Fn(Result<(), SwapChainPanelError>) + 'static, ) -> bool

Detaches the current DXGI swap chain from the published panel.

Source

pub fn observe_surface( &self, callback: impl Fn(SwapChainPanelEvent) + 'static, ) -> ElementObservation

Observes panel metrics and frame rendering across published panel bindings.

Registration is accepted before publication. Each new binding creates a native subscription for that panel, and removal retires the old subscription.

Source§

impl ElementRef<Image>

Source

pub fn request_set_native_source( &self, source: Option<IUnknown>, completion: impl Fn(Result<(), ImageSourceError>) + 'static, ) -> bool

Assigns an application-owned native ImageSource to the published image.

Source

pub fn observe_rasterization_scale( &self, callback: impl Fn(f64) + 'static, ) -> ElementObservation

Observes rasterization scale across the image’s published bindings.

Registration is accepted before publication. Each new binding creates a native subscription after the image enters a live XAML tree.

Source§

impl ElementRef<Grid>

Source

pub fn observe_composition_host( &self, callback: impl Fn(CompositionHostEvent) + 'static, ) -> ElementObservation

Observes an application-owned lifted Composition host across published bindings.

Registration is accepted before publication. Each new binding creates a native subscription for that host, and removal retires the old subscription.

Source

pub fn request_set_child_visual( &self, visual: Option<IUnknown>, completion: impl Fn(Result<(), CompositionHostError>) + 'static, ) -> bool

Assigns an application-owned lifted Composition visual to the host element.

Trait Implementations§

Source§

impl<T> Clone for ElementRef<T>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T> Debug for ElementRef<T>

Source§

fn fmt(&self, formatter: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: ReferenceControl> Default for ElementRef<T>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<T> Eq for ElementRef<T>

Source§

impl<T> PartialEq for ElementRef<T>

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more

Auto Trait Implementations§

§

impl<T> !RefUnwindSafe for ElementRef<T>

§

impl<T> !Send for ElementRef<T>

§

impl<T> !Sync for ElementRef<T>

§

impl<T> !UnwindSafe for ElementRef<T>

§

impl<T> Freeze for ElementRef<T>
where PhantomData<fn() -> T>: Freeze,

§

impl<T> Unpin for ElementRef<T>
where PhantomData<fn() -> T>: Unpin,

§

impl<T> UnsafeUnpin for ElementRef<T>
where PhantomData<fn() -> T>: UnsafeUnpin,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.