[Silverlight 4] Textbox style模擬Textblock 使可以選取、複製

childwindow 做為訊息視窗,使用textblock,可是textbloc無法選取內容及複製,

就改用textbox假裝成textblock

---原本的textblock

<controls:ChildWindow x:Class="ManageBack.Controls.MessageWindows"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls"
Width="200" Height="150"
Title="新信息">
<Grid x:Name="LayoutRoot" Width="140" Height="78">
<StackPanel Orientation="Vertical" >
<TextBlock x:Name="ErrorTextBox" Width="140" Height="45" VerticalAlignment="Center" TextWrapping="Wrap" TextAlignment="Center" Foreground="Red" />
<Button x:Name="OKButton" Click="OKButton_Click" Width="75" Height="23" HorizontalAlignment="Center" Margin="0,5,0,0"
TabIndex="0" Content="确定"/>
</StackPanel>
</Grid>
</controls:ChildWindow>

---原本的textblock

 

ContentPresenter 一定要加x:Name="ContentElement"

指出該control的行為是哪個control的行為

---改成textbox

<controls:ChildWindow x:Class="ManageBack.Controls.MessageWindows"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls"
Width="200" Height="150"
Title="新信息">
<controls:ChildWindow.Resources>
<Style TargetType="TextBox">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<Grid>
<ContentPresenter x:Name="ContentElement"></ContentPresenter>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</controls:ChildWindow.Resources>
<Grid x:Name="LayoutRoot" Width="140" Height="78">
<StackPanel Orientation="Vertical" >
<TextBox x:Name="ErrorTextBox" Width="140" Height="45" VerticalAlignment="Center" TextWrapping="Wrap" TextAlignment="Center" Foreground="Red" IsReadOnly="True"/>
<Button x:Name="OKButton" Click="OKButton_Click" Width="75" Height="23" HorizontalAlignment="Center" Margin="0,5,0,0"
TabIndex="0" Content="确定"/>
</StackPanel>
</Grid>
</controls:ChildWindow>

---改成textbox

 

posted on 2019-11-15 10:11  seako  阅读(111)  评论(0编辑  收藏  举报