2011-02-07 64 views
2

我试图在状态信息弹出窗口中托管多行文本框以显示只读,多行,可滚动的信息。下面的XAML一切正常,除了文本是不可选(因此用户可以复制它)。无法在弹出式窗口中选择WPF文本框中的文本

<!-- 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:Boolean>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> 

在视图模型中相应的属性:

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); 
     } 
    } 

是否托管在弹出的文本框中莫名其妙禁用文本选择,或者是有我的结合的问题吗?我正在替换文本框可以选择的模式窗口中托管的TextBox。

更新:这发生在一个.NET 3.5应用程序中,WPF托管在Win Forms容器中。

+1

我在使用WPF 4项目粘贴此代码,我可以选择在文本框中的文本。 – Zamboni 2011-02-08 18:29:44

回答

0

在什么时候你的控件被实例化了 - 在winforms控件的构造函数中还是在以后的时间?也许你可以尝试Loaded或ControlCreated。

这听起来有点像ElementHost.EnableModelessKeyboardInterop没有被调用时发生的情况,但它不能用弹出框调用。

一种解决方法,可以添加一个“复制”按钮...