-
Notifications
You must be signed in to change notification settings - Fork 13
How to register elements in Panzoom
Ronnie Tran edited this page Jul 21, 2021
·
2 revisions
To enable panning and zooming of an element, you must wrap it with the provided <Panzoom>
component and then provide the <Panzoom>
component with the element's ElementReference
.
For example, I want to enable panning for my <img>
element seen here:
<div class="my-main" style="border-style: solid;">
<img src="https://homepages.cae.wisc.edu/~ece533/images/pool.png" alt="image"/>
</div>
Now we wrap it with the <Panzoom>
component:
<div class="my-main" style="border-style: solid;">
<Panzoom>
<!-- Must set the element's reference (@ref)! -->
<img @ref="@context.ElementReference" src="https://homepages.cae.wisc.edu/~ece533/images/pool.png" alt="image"/>
</Panzoom>
</div>
The <img>
element is now ready to be panned!
If the element already has its @ref
set, then you can register it in the <Panzoom>
component in the @code
or the C# code section.
- Make sure you have a reference (
@ref
) to thePanzoom
component - Set the
ElementReference
property of thePanzoom
component to the element you wish to register for in theOnAfterRender(bool firstRender)
function
See below for an example using the example above:
<div class="my-main" style="border-style: solid;">
<Panzoom @ref="_panzoom">
<img @ref="_elementRef" src="https://homepages.cae.wisc.edu/~ece533/images/pool.png" alt="image"/>
</Panzoom>
</div>
@code {
private Panzoom _panzoom; // # 1. reference to the Panzoom component
private ElementReference _elementRef;
protected override void OnAfterRender(bool firstRender)
{
if (firstRender)
{
_panzoom.ElementReference = _elementRef; // # 2
}
base.OnAfterRender(firstRender);
}
}
...
...