次のようなカスタム要素があります。
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
<Setter Property="Background" Value="Transparent"/>
<Setter Property="Padding" Value="0"/>
<Setter Property="HorizontalContentAlignment" Value="Left"/>
<Setter Property="VerticalContentAlignment" Value="Center"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Label}">
<Grid>
<TextBox Name="textBox"
Grid.ZIndex="1"
Padding="0,3,0,0"
Text="{Binding RelativeSource={RelativeSource AncestorType={x:Type Label}}, Path=Content, UpdateSourceTrigger=PropertyChanged}"
Opacity="0"
IsEnabled="False"
Focusable="True"
/>
<Border Name="boxBorder" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="1" Background="{TemplateBinding Background}" Padding="3,0,0,0" SnapsToDevicePixels="true">
<ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
</Border>
</Grid>
ダブルクリックすると入力フィールド(テキストボックス)に変わるラベルが必要です。したがって、次のようにダブルクリック イベントを定義しました。
<EventTrigger RoutedEvent="MouseDoubleClick">
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetName="textBox"
Storyboard.TargetProperty="Opacity" To="1" Duration="0" />
<BooleanAnimationUsingKeyFrames Duration="0" Storyboard.TargetName="textBox"
Storyboard.TargetProperty="IsEnabled">
<DiscreteBooleanKeyFrame Value="True" KeyTime="0" />
</BooleanAnimationUsingKeyFrames>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
ダブルクリックは正常に機能しますが、テキスト ボックスにフォーカスを移動するにはトリプル クリックを実行する必要があります。ダブルクリックするだけで不透明度が 1 になります。ダブルクリック イベントでフォーカスをテキスト ボックスに移動する方法が見つかりません。