开发者

Unable to select text in WPF TextBox inside a Popup

I'm trying to host a multi-line TextBox in a status information Popup to show read-only, multi-line, scrollable information. The following XAML all works well, except that the text is not selectable (so the user can copy it).

<!-- Status info popup -->
<Popup AllowsTransparency="True" PopupAnimation="Fade" Placement="Center" StaysOpen="False"
       PlacementTarget="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type v:ModuleView}}}" 
       IsOpen="{Binding ShowingStatusInformation}">
    <Border CornerRadius="5">
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="Auto" />
            </Grid.ColumnDefinitions>

            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="*" />
            </Grid.RowDefinitions>

            <TextBlock Text="Status Information"
                       Grid.Column="0" Grid.Row="0" VerticalAlignment="Center" />                        
            <Button Content="OK" IsDefault="True" Command="{Binding ToggleStatusInfoCommand}"
                    HorizontalAlignment="Right" Margin="0 5" Padding="20 3" 
                    Grid.Column="1" Grid.Row="0" VerticalAlignment="Center">
                <Button.CommandParameter><sys:Boo开发者_如何学Clean>False</sys:Boolean></Button.CommandParameter>
            </Button>

            <TextBox IsReadOnly="True" Text="{Binding StatusInformation}" 
                     Margin="6 6 6 3" Grid.Column="0" Grid.ColumnSpan="2" Grid.Row="1"
                     TextWrapping="Wrap" VerticalScrollBarVisibility="Auto" 
                     MaxHeight="300" />
        </Grid>
    </Border>
</Popup>

The corresponding properties on the view model:

    public string StatusInformation
    {
        get { return _statusInformation; }
        set
        {
            _statusInformation = value;
            _propertyChangedHelper.NotifyPropertyChanged(this, () => StatusInformation);
        }
    }

    public bool ShowingStatusInformation
    {
        get { return _showingStatusInformation; }
        set
        {
            _showingStatusInformation = value;
            _propertyChangedHelper.NotifyPropertyChanged(this, () => ShowingStatusInformation);
        }
    }

Does hosting the text box in a Popup somehow disable text selection, or is there a problem with my binding? I'm replacing a TextBox hosted in a modal window where the text is selectable.

Update: this is happening in a .NET 3.5 application with WPF hosted inside a Win Forms container.


At what point is your control instantiated - in the constructor of the winforms control or at a later time? Maybe you could try for Loaded or ControlCreated.

It sounds a bit like what is happening when ElementHost.EnableModelessKeyboardInterop has not been called, but it is not callable with a popup.

A workaround could be adding a 'Copy' button...

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜