WPF 基础


类继承图

命令

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>fewBold>, we happy <Bold>fewBold>, we band of <Underline>brothersUnderline>;
For he to-day that sheds his <Italic>bloodItalic> with me
Shall be my <Underline>brotherUnderline>; be he ne'er so <Italic>vileItalic>,
This day shall <Bold>gentleBold> his <Italic>conditionItalic>;"
        TextBlock>
WPF