先日のサンプルを、XAML で CommandBinding を設定するように修正してみた
<Window x:Class="WpfSample.EditDialog" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:WpfSample="clr-namespace:WpfSample" Title="EditDialog" Height="400" Width="400" Background="#303030"> <Window.Resources> <Style x:Key="{x:Type Button}" TargetType="{x:Type Button}"> <Setter Property="Margin" Value="2"/> <Setter Property="Height" Value="28"/> <Setter Property="Foreground" Value="#F0F0F0"/> <Setter Property="Background" Value="#0593E2"/> </Style> <Style x:Key="{x:Type TextBox}" TargetType="{x:Type TextBox}"> <Setter Property="Background" Value="#444444"/> <Setter Property="Foreground" Value="#F0F0F0"/> <Setter Property="Margin" Value="2"/> <Setter Property="Height" Value="28"/> </Style> <Style x:Key="{x:Type ComboBox}" TargetType="{x:Type ComboBox}"> <Setter Property="Margin" Value="2"/> <Setter Property="Height" Value="28"/> <Setter Property="Background" Value="#444444"/> <Setter Property="Foreground" Value="#F0F0F0"/> </Style> <Style x:Key="{x:Type Label}" TargetType="{x:Type Label}"> <Setter Property="Foreground" Value="#F0F0F0"/> </Style> </Window.Resources> <DockPanel LastChildFill="True"> <StackPanel DockPanel.Dock="Bottom" Orientation="Horizontal" FlowDirection="RightToLeft"> <Button Width="100" Content="キャンセル"/> <Button Width="100" Content="OK"/> </StackPanel> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="150"/> <ColumnDefinition Width="*"/> <ColumnDefinition Width="50"/> </Grid.ColumnDefinitions> <Grid.RowDefinitions> <RowDefinition/> <RowDefinition/> <RowDefinition/> <RowDefinition/> <RowDefinition/> <RowDefinition/> <RowDefinition/> <RowDefinition/> </Grid.RowDefinitions> <Label Grid.Column="0" Grid.Row="0" Content="名前"/> <Label Grid.Column="0" Grid.Row="1" Content="ファイル名"/> <Label Grid.Column="0" Grid.Row="2" Content="パラメータ"/> <Label Grid.Column="0" Grid.Row="3" Content="作業フォルダ"/> <Label Grid.Column="0" Grid.Row="4" Content="実行時の大きさ"/> <Label Grid.Column="0" Grid.Row="5" Content="ツールチップ"/> <Label Grid.Column="0" Grid.Row="6" Content="ショートカットキー"/> <Label Grid.Column="0" Grid.Row="7" Content="ホットキー"/> <TextBox Name="titleTextBox" Grid.Column="1" Grid.Row="0" Grid.ColumnSpan="2" Text="{Binding Title}"/> <TextBox Name="fileNameTextBox" Grid.Column="1" Grid.Row="1" Text="{Binding FileName}"/> <TextBox Name="parameterTextBox" Grid.Column="1" Grid.Row="2" Grid.ColumnSpan="2" Text="{Binding Arguments}"/> <TextBox Name="workingDirTextBox" Grid.Column="1" Grid.Row="3" Grid.ColumnSpan="2" Text="{Binding WorkingDirectory}"/> <ComboBox Name="windowSizeComboBox" Grid.Column="1" Grid.Row="4" Grid.ColumnSpan="2" SelectedIndex="0" > <ComboBoxItem Content="通常のウィンドウ"/> <ComboBoxItem Content="最大化"/> <ComboBoxItem Content="最小化"/> </ComboBox> <TextBox Name="toolTipTextBox" Grid.Column="1" Grid.Row="5" Grid.ColumnSpan="2"/> <TextBox Name="shortcutKeyTextBox" Grid.Column="1" Grid.Row="6"/> <TextBox Name="hotKeyTextBox" Grid.Column="1" Grid.Row="7" /> <Button Name="referenceButton" Grid.Column="2" Grid.Row="1" Content="参照" Command="{x:Static WpfSample:EditDialog.ReferenceCommand}"> <!-- この部分を新たに追加しました!! --> <!-- CommandBinding を XAML で記述 --> <Button.CommandBindings> <CommandBinding Command="{x:Static WpfSample:EditDialog.ReferenceCommand}" CanExecute="referenceCommandBinding_CanExecute" Executed="referenceCommandBinding_Executed"/> </Button.CommandBindings> </Button> <Button Grid.Column="2" Grid.Row="6" Content="クリア"/> <Button Grid.Column="2" Grid.Row="7" Content="クリア"/> </Grid> </DockPanel> </Window>
今日は手抜きヽ(´ー`)ノ