开发者

how to do I Silverlight read-only edit control, which I can cut and paste from?

开发者 https://www.devze.com 2022-12-21 18:24 出处:网络
I have a master-detail view, which I created in Silverlight 2. So, I\'m not us开发者_开发技巧ing the new master-detail stuff available in SL3.

I have a master-detail view, which I created in Silverlight 2. So, I'm not us开发者_开发技巧ing the new master-detail stuff available in SL3.

So basically you have a grid at the top, and at the bottom you have the details for whatever item you select in the grid appearing in a panel.

I did not want the user to be able to accidentally change the values in the fields, so I went with labels.

the user asked for cut and paste :) Because I could not get the focus of that label, I implemented a non standard cut and paste solution by having the user right click in the label, and it puts it on the clipboard. The user then can do Ctrl+V to paste it somewhere else or in any other windows app.

However, now there are some users saying they need to be able to select a part of the item in the label, say the first 3 characters or the last 2 using the mouse or keyboard. So, it seems like the label needs to be replaced with an textbox control.

The problem doing this seems to be that if I set the textbox to readonly I cannot cut and paste from it. So, sure it's a textbox, and you cannot edit it, but you cannot copy/select from it either.

Is there another way to do this?

thanks for any help you can provide,

Sincerely, J__


TextBox should be fine. I can't speak for Silverlight 2, and maybe there's an issue with SL2 and TextBox, but I just built a sample Silverlight 3 app, added a TextBox, and set Text="some text" and IsReadOnly="True". I'm able to select any portion of the text (via mouse), and ctrl-c it to put it on the clipboard.

Here's the (very simple) xaml I set up, with no code-behind. I'm able to select any portion of the text and copy it to the clipboard:

<UserControl
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="layouttest.MainPage"
Width="640" Height="480">
<Grid x:Name="LayoutRoot" Background="White">
    <TextBox Width="200" Height="30" Text="See if you can copy this"
    TextWrapping="Wrap" IsReadOnly="True"  />
</Grid>

0

精彩评论

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

关注公众号