tags:

views:

116

answers:

1

I have a master-detail view, which I created in Silverlight 2. So, I'm not using 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__

+1  A: 

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>

David Makogon
thanks for the response. We started this codebase on SL2 and then updated to SL3. Maybe it was that? I can't imagine why i would have done the 'custom' right click approach if I couldn't do it the other (simpler) way.thanks so much for the response.J
J__
Just curious - if you create a brand new SL3 app and add the grid above to your main form, are you able to copy out of the textbox?
David Makogon
I am able to do that now. Thanks again.
J__