WPF InputScope 在 Dialoghost .NET 6 上不起作用

Posted

技术标签:

【中文标题】WPF InputScope 在 Dialoghost .NET 6 上不起作用【英文标题】:WPF InputScope not working on Dialoghost .NET 6 【发布时间】:2021-12-05 02:22:35 【问题描述】:

我有一个带有文本框的 dialogHost,我需要 inputscope 为数字,因为使用了 TouchKeyboard,在用户控件中它工作正常,但在对话框中键盘布局没有改变。

   <materialDesign:DialogHost x:Name="dgh_addProduct" CloseOnClickAway="True" IsOpen="Binding AddProduct" Grid.RowSpan="4" >
            <materialDesign:DialogHost.DialogContent>
                <StackPanel Background="DynamicResource MaterialDesignPaper">
                    <TextBox  materialDesign:HintAssist.Hint="Cantidad" BorderThickness="2"
                                BorderBrush="DynamicResource MaterialDesignDivider"
                            Style="StaticResource MaterialDesignOutlinedTextBox" Width="200" Margin="16"
                            PreviewTextInput="TextBoxNumeric_PreviewTextInput" InputScope="Number" />
                    <StackPanel Orientation="Horizontal" HorizontalAlignment="Center" Margin="16">
                        <Button Style="StaticResource MaterialDesignFlatDarkBgButton"
                                Background="Red" BorderBrush="Transparent" Content="Close" Width="100"
                                Command="Binding CloseAddProductCommand"  Margin=" 8 0 16 0"/>
                        <Button  Style="StaticResource MaterialDesignFlatAccentBgButton"
                                BorderBrush="Transparent" Content="Agregar" Width="100"
                                Command="Binding CloseAddProductCommand" Margin=" 16 0 8 0"/>
                    </StackPanel>
                   
                </StackPanel>
            </materialDesign:DialogHost.DialogContent>


        </materialDesign:DialogHost>

【问题讨论】:

【参考方案1】:

我发现解决方案将 Embedded 样式添加到对话框主机,如下所示:

<materialDesign:DialogHost x:Name="dgh_addProduct" CloseOnClickAway="True" IsOpen="Binding AddProduct"
                Grid.RowSpan="4" Style="StaticResource MaterialDesignEmbeddedDialogHost">
            <materialDesign:DialogHost.DialogContent>
                <StackPanel Background="DynamicResource MaterialDesignPaper">
                    <TextBox  materialDesign:HintAssist.Hint="Cantidad" BorderThickness="2"
                                BorderBrush="DynamicResource MaterialDesignDivider"
                            Style="StaticResource MaterialDesignOutlinedTextBox" Width="200" Margin="16"
                            PreviewTextInput="TextBoxNumeric_PreviewTextInput" InputScope="Number" />
                    <StackPanel Orientation="Horizontal" HorizontalAlignment="Center" Margin="16">
                        <Button Style="StaticResource MaterialDesignFlatDarkBgButton"
                                Background="Red" BorderBrush="Transparent" Content="Close" Width="100"
                                Command="Binding CloseAddProductCommand"  Margin=" 8 0 16 0"/>
                        <Button  Style="StaticResource MaterialDesignFlatAccentBgButton"
                                BorderBrush="Transparent" Content="Agregar" Width="100"
                                Command="Binding CloseAddProductCommand" Margin=" 16 0 8 0"/>
                    </StackPanel>
                   
                </StackPanel>
            </materialDesign:DialogHost.DialogContent>


        </materialDesign:DialogHost>

现在它可以识别输入范围并更改触摸键盘布局。

【讨论】:

以上是关于WPF InputScope 在 Dialoghost .NET 6 上不起作用的主要内容,如果未能解决你的问题,请参考以下文章

C#winform - 相当于InputScope

UWP的TextBox和PasswordBox使用输入范围更改触摸键盘InputScope

无法将String转换为String

如何在所有应用程序中仅使用 NumericPin 键盘? UWP

如何使用仅接受数字的输入范围创建 PasswordBox?

Windows UWP中带有“Enter”键的虚拟键盘Numpad