开发者

Disable Drag-drop from TextBox

I have a WPF textBox that is declared as ReadOnly

<TextBox IsReadOnly="True" IsTabStop="False" Width="200" /&g开发者_如何转开发t;

So, User can not write anything into the TextBox or delete the content but it still allows user to drag the text from this textbox and drop it in any other textbox that caused the text removed from the first textbox(the read-only one) and thats unexpected. Is it a bug? how can I get rid of this?


I tried the following code :

<StackPanel>
    <TextBox IsReadOnly="True">Hello</TextBox>
    <TextBox></TextBox>
</StackPanel>

When I drag-and-drop the text (after selection) from the first TexbtBox to the second one, the text is copied, but not removed from the first TextBox. I tried it under .NET 3.5 and .NET 4.0 targets.

If you want to get rid of your bug without trying to understand it (since it shouldn't happen), you can just put an empty control (Canvas will be ok) on top of your TextBox, with its Background property set to transparent.

<Grid>
    <TextBox IsReadOnly="True" IsTabStop="False" Width="200" />
    <Canvas Background="Transparent"/>
</Grid>

But the text won't be selectable anymore...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜