2011-02-07 68 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沒有被調用時發生的情況,但它不能用彈出框調用。

一種解決方法,可以添加一個「複製」按鈕...