ファイルを選択するための[参照]ボタンと、選択したファイルへのパスを視覚化するためのテキストボックスを備えた小さなユーザーコントロールがあります。
<TextBox Text="{Binding FilePath, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
<Button Content="Browse" cal:Message.Attach="SelectInstallationPointsFile" />
2つのボタンを備えたウィンドウとしてウィンドウダイアログから開始するコントロール-OK
およびCancel
ウィンドウリソーススタイル(コードの簡略化されたバージョン)で定義されたコントロール:
<Style TargetType="{x:Type Window}">
...
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Window}">
...
<ContentControl Content="{TemplateBinding Content}" ContentTemplate="{TemplateBinding ContentTemplate}" /> <!-- here will be the user control -->
<Button IsDefault="True" Content="OK" cal:Message.Attach="Apply" />
<Button IsCancel="True" cal:Message.Attach="Cancel" />
...
</Style>
ダイアログの表示(緑のセクション-ウィンドウ、赤-ユーザーコントロール):
問題は次のとおりです。ボタンをクリックしてから、ユーザーコントロールからボタンEnter
に反応しますが、ウィンドウダイアログからのボタンには反応しません。Browse
OK
OK
IsDefault="True"