command WPF
-
קומנד יכול להיות מאוד שימושי עבור עריכת טקסט בתיבת טקסט עשיר למשל כך:
<StackPanel Orientation="Horizontal" Height="24" Background="{Binding ElementName=FsRichTextBoxControl, Path=ToolbarBackground}" > <!-- Font drop-down code from http://www.bennedik.de/2007/10/wpf-fast-font-drop-down-list.html --> <!-- Font family combo box --> <ComboBox x:Name="FontFamilyCombo" Height="23" Width="100" Margin="5,2,0,2" IsEditable="True" SelectionChanged="OnFontFamilyComboSelectionChanged"> <ComboBox.ItemsPanel> <ItemsPanelTemplate> <VirtualizingStackPanel Width="250" /> </ItemsPanelTemplate> </ComboBox.ItemsPanel> <ComboBox.ItemTemplate> <DataTemplate> <TextBlock Text="{Binding}" FontFamily="{Binding}" FontSize="15" Height="20"/> </DataTemplate> </ComboBox.ItemTemplate> </ComboBox> <!-- Font size combo box --> <ComboBox x:Name="FontSizeCombo" Height="23" Width="40" Margin="5,2,5,2" IsEditable="True" SelectionChanged="OnFontSizeComboSelectionChanged" /> <Button Command="ApplicationCommands.Cut" CommandTarget="{Binding ElementName=TextBox}" ToolTip="Cut" Template="{StaticResource FlatButtonControlTemplate}" Margin="0,1,0,1"> <Image Source="Images\editcut.png" Stretch="None" SnapsToDevicePixels="True" /> </Button> <Button Command="ApplicationCommands.Copy" CommandTarget="{Binding ElementName=TextBox}" ToolTip="Copy" Template="{StaticResource FlatButtonControlTemplate}" Margin="0,1,0,1"> <Image Source="Images\editcopy.png" Stretch="None" SnapsToDevicePixels="True" /> </Button> <Button Command="ApplicationCommands.Paste" CommandTarget="{Binding ElementName=TextBox}" ToolTip="Paste" Template="{StaticResource FlatButtonControlTemplate}" Margin="0,1,0,1"> <Image Source="Images\editpaste.png" Stretch="None" SnapsToDevicePixels="True" /> </Button> <Button Command="ApplicationCommands.Undo" CommandTarget="{Binding ElementName=TextBox}" ToolTip="Undo" Template="{StaticResource FlatButtonControlTemplate}" Margin="0,1,0,1"> <Image Source="Images\editundo.png" Stretch="None" SnapsToDevicePixels="True" /> </Button> <Button Command="ApplicationCommands.Redo" CommandTarget="{Binding ElementName=TextBox}" ToolTip="Redo" Template="{StaticResource FlatButtonControlTemplate}" Margin="0,1,0,1"> <Image Source="Images\editredo.png" Stretch="None" SnapsToDevicePixels="True" /> </Button> <Image Source="Images\separator.png" Stretch="None" SnapsToDevicePixels="True" /> <ToggleButton x:Name="BoldButton" Command="EditingCommands.ToggleBold" CommandTarget="{Binding ElementName=TextBox}" ToolTip="Bold" Template="{StaticResource FlatToggleButtonControlTemplate}" Margin="0,1,0,1"> <Image Source="Images\fontbold.png" Stretch="None" SnapsToDevicePixels="True" /> </ToggleButton> <ToggleButton x:Name="ItalicButton" Command="EditingCommands.ToggleItalic" CommandTarget="{Binding ElementName=TextBox}" ToolTip="Italic" Template="{StaticResource FlatToggleButtonControlTemplate}" Margin="0,1,0,1"> <Image Source="Images\fontitalic.png" Stretch="None" SnapsToDevicePixels="True" /> </ToggleButton> <ToggleButton x:Name="UnderlineButton" Command="EditingCommands.ToggleUnderline" CommandTarget="{Binding ElementName=TextBox}" ToolTip="Underline" Template="{StaticResource FlatToggleButtonControlTemplate}" Margin="0,1,0,1"> <Image Source="Images\fontunderline.png" Stretch="None" SnapsToDevicePixels="True" /> </ToggleButton> <Image Source="Images\separator.png" Stretch="None" SnapsToDevicePixels="True" /> <Button ToolTip="Format as normal (non-code) text" Template="{StaticResource FlatButtonControlTemplate}" Margin="0,1,0,1" Visibility="{Binding Path=CodeControlsVisibility, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}}" Click="OnNormalTextClick"> <Image Source="Images\normaltext.png" Stretch="None" SnapsToDevicePixels="True" /> </Button> <Button ToolTip="Format as code block" Template="{StaticResource FlatButtonControlTemplate}" Margin="0,1,0,1" Visibility="{Binding Path=CodeControlsVisibility, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}}" Click="OnCodeBlockClick"> <Image Source="Images\codeblock.png" Stretch="None" SnapsToDevicePixels="True" /> </Button> <Button ToolTip="Format as inline code" Template="{StaticResource FlatButtonControlTemplate}" Margin="0,1,0,1" Visibility="{Binding Path=CodeControlsVisibility, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}}" Click="OnInlineCodeClick"> <Image Source="Images\codeinline.png" Stretch="None" SnapsToDevicePixels="True" /> </Button> <Image Source="Images\separator.png" Stretch="None" SnapsToDevicePixels="True" Visibility="{Binding Path=CodeControlsVisibility, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}}" /> <ToggleButton x:Name="LeftButton" Command="EditingCommands.AlignLeft" CommandTarget="{Binding ElementName=TextBox}" ToolTip="Align Left" Template="{StaticResource FlatToggleButtonControlTemplate}" Margin="0,1,0,1" Click="OnAlignmentButtonClick"> <Image Source="Images\alignleft.png" Stretch="None" SnapsToDevicePixels="True" /> </ToggleButton> <ToggleButton x:Name="CenterButton" Command="EditingCommands.AlignCenter" CommandTarget="{Binding ElementName=TextBox}" ToolTip="Align Center" Template="{StaticResource FlatToggleButtonControlTemplate}" Margin="0,1,0,1" Click="OnAlignmentButtonClick"> <Image Source="Images\aligncenter.png" Stretch="None" SnapsToDevicePixels="True" /> </ToggleButton> <ToggleButton x:Name="RightButton" Command="EditingCommands.AlignRight" CommandTarget="{Binding ElementName=TextBox}" ToolTip="Align Right" Template="{StaticResource FlatToggleButtonControlTemplate}" Margin="0,1,0,1" Click="OnAlignmentButtonClick"> <Image Source="Images\alignright.png" Stretch="None" SnapsToDevicePixels="True" /> </ToggleButton> <ToggleButton x:Name="JustifyButton" Command="EditingCommands.AlignJustify" CommandTarget="{Binding ElementName=TextBox}" ToolTip="Align Justify" Template="{StaticResource FlatToggleButtonControlTemplate}" Margin="0,1,0,1" Click="OnAlignmentButtonClick"> <Image Source="Images\alignjustify.png" Stretch="None" SnapsToDevicePixels="True" /> </ToggleButton> <Image Source="Images\separator.png" Stretch="None" SnapsToDevicePixels="True" /> <ToggleButton x:Name="BulletsButton" Command="EditingCommands.ToggleBullets" CommandTarget="{Binding ElementName=TextBox}" ToolTip="Bullets" Template="{StaticResource FlatToggleButtonControlTemplate}" Margin="0,1,0,1" Click="OnListButtonClick"> <Image Source="Images\listbullets.png" Stretch="None" SnapsToDevicePixels="True" /> </ToggleButton> <ToggleButton x:Name="NumberingButton" Command="EditingCommands.ToggleNumbering" CommandTarget="{Binding ElementName=TextBox}" ToolTip="Numbering" Template="{StaticResource FlatToggleButtonControlTemplate}" Margin="0,1,0,1" Click="OnListButtonClick"> <Image Source="Images\listnumbers.png" Stretch="None" SnapsToDevicePixels="True" /> </ToggleButton> <Image Source="Images\separator.png" Stretch="None" /> <Button Command="EditingCommands.IncreaseIndentation" CommandTarget="{Binding ElementName=TextBox}" ToolTip="Increase Indentation" Template="{StaticResource FlatButtonControlTemplate}" Margin="0,1,0,1"> <Image Source="Images\indentincrease.png" Stretch="None" SnapsToDevicePixels="True" /> </Button> <Button Command="EditingCommands.DecreaseIndentation" CommandTarget="{Binding ElementName=TextBox}" ToolTip="Decrease Indentation" Template="{StaticResource FlatButtonControlTemplate}" Margin="0,1,0,1"> <Image Source="Images\indentdecrease.png" Stretch="None" SnapsToDevicePixels="True" /> </Button> </StackPanel>
ראה שיש כאן שתי קבוצות של פקודות EditingCommands ו ApplicationCommands
פורסם במקור בפורום CODE613 ב09/03/2014 22:36 (+02:00)