为什么我的WPF文本框和QUOT;还挺"只读? [英] Why is my WPF textbox "kinda" readonly?

查看:112
本文介绍了为什么我的WPF文本框和QUOT;还挺"只读?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个文本框在WPF是一个DataTemplate一个列表框的一部分。在该文本框我可以删除,退格键,空格键,但我不能输入新单词,字母或数字。我可以粘贴从记事本,虽然。

我在想什么吗?

 <列表框Grid.Column =1
         的ItemsSource ={结合详细}
         VirtualizingStackPanel.VirtualizationMode =回收
         Horizo​​ntalContentAlignment =拉伸>
            < ListBox.Resources>
                < D​​ataTemplate中数据类型={X:类型实体:RADetailEntry}>
                    <电网>
                        < Grid.ColumnDefinitions>
                            < ColumnDefinition宽度=自动/>
                            &所述; ColumnDefinition宽度=*/>
                        < /Grid.ColumnDefinitions>

                        &所述;组合框Grid.Column =0/>
                        <文本框Grid.Column =1的IsReadOnly =假的IsEnabled =真
                                 文本={绑定路径=描述,模式=双向}TextWrapping =自动换行
                                 的Horizo​​ntalAlignment =拉伸VerticalAlignment =拉伸TextAlignment =左/>
                    < /网格>
                < / DataTemplate中>
            < /ListBox.Resources>
        < /列表框>
 

解决方案

我遇到一个问题非常类似。做了一些研究之后,我发现在MSDN中列出了类似的问题:

<一个href="http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/c68d5f3c-c8cc-427d-82e3-6135d075a304/">http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/c68d5f3c-c8cc-427d-82e3-6135d075a304/

据答案后,这个问题必须与WPF和WinForms有两个非常不同的处理文字输入方式。幸运的是,上面列出的职位提供了以下解决方案:

在启动窗口,使用ElementHost.EnableModelessKeyboardInterop(窗口1)。请注意,这是一个静态方法 - 你不必实例化的ElementHost类

例如,

 窗口窗口1 =新窗口();
ElementHost.EnableModelessKeyboardInterop(窗口1);
window1.Show();
 

这解决了这个问题对我来说。希望这有助于。

I have a text box in WPF that is part of a datatemplate for a listbox. In that text box I can delete, backspace, spacebar, but I can NOT type in new words, letters or numbers. I CAN paste from notepad though.

What am I missing here?

 <ListBox Grid.Column="1"
         ItemsSource="{Binding Details}"
         VirtualizingStackPanel.VirtualizationMode="Recycling"
         HorizontalContentAlignment="Stretch" >
            <ListBox.Resources>
                <DataTemplate DataType="{x:Type Entities:RADetailEntry}">
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto"/>
                            <ColumnDefinition Width="*"/>
                        </Grid.ColumnDefinitions>

                        <ComboBox Grid.Column="0" />
                        <TextBox Grid.Column="1" IsReadOnly="False" IsEnabled="True" 
                                 Text="{Binding Path=Description, Mode=TwoWay}" TextWrapping="Wrap"
                                 HorizontalAlignment="Stretch" VerticalAlignment="Stretch" TextAlignment="Left"  />
                    </Grid>
                </DataTemplate>
            </ListBox.Resources>
        </ListBox>

解决方案

I was encountering a problem very similar to this. After doing a little research, I found a similar problem listed in MSDN:

http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/c68d5f3c-c8cc-427d-82e3-6135d075a304/

According to the answer to the post, the problem has to do with WPF and WinForms having two very different ways of handling text input. Fortunately, the post listed above gives the following solution:

When launching the window, use ElementHost.EnableModelessKeyboardInterop(window1). Note that this is a static method - you do not have to instantiate the ElementHost class.

For example,

Window window1 = new Window();
ElementHost.EnableModelessKeyboardInterop(window1);
window1.Show();

This solved the problem for me. Hope this helps.

这篇关于为什么我的WPF文本框和QUOT;还挺&QUOT;只读?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆