无法在弹出窗口内的 WPF 文本框中选择文本
我试图在状态信息弹出窗口中托管一个多行文本框,以显示只读、多行、可滚动信息。以下 XAML 运行良好,但文本不可选择(因此用户可以复制它)。
<!-- 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);
}
}
在弹出窗口中托管文本框是否会以某种方式禁用文本选择,或者我的绑定是否存在问题?我正在替换托管在模式窗口中的文本框,其中文本可供选择。
更新:这是在 Win Forms 容器内托管 WPF 的 .NET 3.5 应用程序中发生的情况。
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: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>
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的控件在什么时候实例化 - 在 winforms 控件的构造函数中还是稍后?也许你可以尝试 Loaded 或 ControlCreated。
这听起来有点像 ElementHost.EnableModelessKeyboardInterop 尚未被调用时发生的情况,但它不能通过弹出窗口调用。
解决方法可能是添加“复制”按钮...
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...