Recently, I have been troubled by various things and my blog has not been updated. Today I will share a simple technique.
When loading a page, you need to focus on a textbox. This is easy to implement in codebehind. If mvvm mode is used, this is irrelevant to viewmodel, but it can be implemented using behavior.
Targetedtriggeraction <t> is used here. This T must be a control, because focus can be used in this way:
Public ClassFocusonevent: targetedtriggeraction <control>
{
Protected Override VoidInvoke (ObjectO)
{
Htmlpage. plugin. Focus ();
Target. Focus ();
}
}
We can add a defaulttrigger for it to trigger in the loaded event.
[Defaulttrigger (Typeof(Frameworkelement ),Typeof(Eventtrigger ),"Loaded")]
Now that behavior is defined, reference this behavior on the UI.
<I: interaction. triggers>
<I: eventtrigger>
<Local: focusonevent Targetname= "Textbox1"/>
</I: eventtrigger>
</I: interaction. triggers>
In this way, after the page is loaded successfully, textbox1 will be set as the default focus control.
This article is here to help you.