मुझे अपने विंडोज स्टोर ऐप में WebView
के भीतर contentEditable
आधारित संपादक मिला है। कुछ कीबोर्ड शॉर्टकट्स और बटन खोलने के लिए MessageDialog
का कारण बन सकते हैं। जब यह संवाद खारिज कर दिया जाता है, तो संपादक को अब फोकस नहीं होता है। मैंने हर तरह से ध्यान केंद्रित करने की कोशिश की है, और यह काम नहीं करेगा। यहां एक नमूना ऐप है।मैसेजडियलॉग बंद होने के बाद वेबव्यू पर फ़ोकस करना
MainPage.xaml
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<WebView x:Name="Editor" Margin="200"></WebView>
</Grid>
<Page.BottomAppBar>
<CommandBar x:Name="CommandBar_Editor" Visibility="Visible">
<AppBarButton Label="Debug" Icon="Setting">
<AppBarButton.Flyout>
<MenuFlyout>
<MenuFlyoutItem Text="show dialog, then focus" Click="MenuFlyoutItem_Click_1"/>
</MenuFlyout>
</AppBarButton.Flyout>
</AppBarButton>
</CommandBar>
</Page.BottomAppBar>
</Page>
MainPage.xaml.cs
public sealed partial class MainPage : Page
{
public MainPage()
{
this.InitializeComponent();
}
protected override void OnNavigatedTo(NavigationEventArgs e)
{
base.OnNavigatedTo(e);
Editor.NavigateToString("<script type='text/javascript'>function focus_please(){ document.getElementById('editor').focus(); }</script><div id='editor' contentEditable='true'>It was the best of times, it was the worst of times</div>");
}
private async void MenuFlyoutItem_Click_1(object sender, RoutedEventArgs e)
{
MessageDialog dialog = new MessageDialog("this should set focus to editor on close", "test");
UICommand okCommand = new UICommand("OK");
dialog.Commands.Add(okCommand);
IUICommand response = await dialog.ShowAsync();
if (response == okCommand)
{
Editor.Focus(FocusState.Programmatic);
// I've also tried:
// FocusState.Keyboard
// FocusState.Pointer
// FocusState.Unfocused
// this calls JS within the HTML to focus the contentEditable div
await Editor.InvokeScriptAsync("focus_please", null);
}
}
}
मुझे ऐसा लगता है कि WebView
ध्यान केंद्रित है, लेकिन
अद्यतन:
ब्रायन के कोड में नीचे दिए गए उत्तर से जोड़ने के लिए मेरा उदाहरण अपडेट किया गया है, लेकिन यह अभी भी काम नहीं कर रहा है।
नोट संदेशडिअलॉग को खारिज करने के बाद, यदि मैं Tab
दबाता हूं तो संपादक दो बार सक्रिय हो जाता है।
अद्यतन 2:
जब नेविगेट करने के लिए टच स्क्रीन का उपयोग नीचे ब्रायन के जवाब काम करता है। हालांकि माउस और कीबोर्ड का उपयोग करते समय, contentEditable
तत्व फोकस नहीं करता है। मैंने इस पर एक समाधान की तलाश की है जो टच स्क्रीन या माउस/कीबोर्ड कॉम्बो
मैं वेबव्यू में दी गई सामग्री और वेबव्यू ही ध्यान केंद्रित की कोशिश की है है, वे न तो अलग से है और न ही एक साथ – roryok
क्या जावास्क्रिप्ट आप की कोशिश की है काम करते हैं? –
मैंने 'document.getElementById ('editor') की कोशिश की है। फोकस() ', मैंने jquery's' $ ("# editor") की कोशिश की है। फोकस()' और मैंने window.location.hash को सेट करने का प्रयास किया है। जैसा आपने ऊपर किया था। (इसके अलावा, यह * दो शहरों का एक कहानी है! *) – roryok