类继承图
命令
CommandTarget属性可以用来重新设置命令目标
<StackPanel> <TextBox Name="txtSomeText" Width="220" Height="25" Margin="10"/> <Button Content="Paste" Command="ApplicationCommands.Paste" CommandTarget="{Binding ElementName=txtSomeText}" Margin="10" Padding="10,3" HorizontalAlignment="Center" /> </StackPanel>
本例点击按钮时,文本框会自带粘贴,不需要后台代码
另一个场景就是上下文菜单
<MenuItem Command="{x:Static loc:MainWindow.GreetUserCommand}" CommandTarget="{Binding Path=PlacementTarget, RelativeSource={RelativeSource AncestorType={x:Type ContextMenu}}}"/>
文本格式
<TextBlock Margin="10" Height="100" FontSize="14" Width="290" TextWrapping="Wrap"> We <Bold>few</Bold>, we happy <Bold>few</Bold>, we band of <Underline>brothers</Underline>; For he to-day that sheds his <Italic>blood</Italic> with me Shall be my <Underline>brother</Underline>; be he ne'er so <Italic>vile</Italic>, This day shall <Bold>gentle</Bold> his <Italic>condition</Italic>;" </TextBlock>
ListView 使用 WrapPanel 需要禁用 ListView 的水平滚动,才能实现自动换行