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>
impl<T: ReferenceControl> ElementRef<T>
Source§impl<T: FocusControl> ElementRef<T>
impl<T: FocusControl> ElementRef<T>
Sourcepub fn request_focus(&self) -> bool
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.
Sourcepub fn request_focus_result(
&self,
completion: impl Fn(Result<bool, FocusError>) + 'static,
) -> bool
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>
impl ElementRef<WebView2>
Sourcepub fn request_core_web_view2(
&self,
completion: impl Fn(Result<IUnknown, WebView2Error>) + 'static,
) -> bool
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>
impl ElementRef<SwapChainPanel>
Sourcepub fn request_set_swap_chain(
&self,
swap_chain: IUnknown,
completion: impl Fn(Result<(), SwapChainPanelError>) + 'static,
) -> bool
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.
Sourcepub fn request_clear_swap_chain(
&self,
completion: impl Fn(Result<(), SwapChainPanelError>) + 'static,
) -> bool
pub fn request_clear_swap_chain( &self, completion: impl Fn(Result<(), SwapChainPanelError>) + 'static, ) -> bool
Detaches the current DXGI swap chain from the published panel.
Sourcepub fn observe_surface(
&self,
callback: impl Fn(SwapChainPanelEvent) + 'static,
) -> ElementObservation
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>
impl ElementRef<Image>
Sourcepub fn request_set_native_source(
&self,
source: Option<IUnknown>,
completion: impl Fn(Result<(), ImageSourceError>) + 'static,
) -> bool
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.
Sourcepub fn observe_rasterization_scale(
&self,
callback: impl Fn(f64) + 'static,
) -> ElementObservation
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>
impl ElementRef<Grid>
Sourcepub fn observe_composition_host(
&self,
callback: impl Fn(CompositionHostEvent) + 'static,
) -> ElementObservation
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.
Sourcepub fn request_set_child_visual(
&self,
visual: Option<IUnknown>,
completion: impl Fn(Result<(), CompositionHostError>) + 'static,
) -> bool
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.