0

Window をオーバーライドするカスタム コントロールがあります。

public class Window : System.Windows.Window
{
    static Window()
    {
        DefaultStyleKeyProperty.OverrideMetadata(typeof(Window), new System.Windows.FrameworkPropertyMetadata(typeof(Window)));                        
    }
    ...
}

また、次のスタイルもあります。

<Style TargetType="{x:Type Controls:Window}" BasedOn="{StaticResource {x:Type Window}}">
    <Setter Property="WindowStyle"
            Value="None" />        
    <Setter Property="Padding"
            Value="5" />
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type Controls:Window}">
 ...

残念ながら、これにより、ウィンドウのコンテンツに対する Validation.ErrorEvent の伝播が中断されます。つまり、私のウィンドウは問題なくイベントを受け取ることができますが、標準のウィンドウ (または誰でも) がそれを処理する方法を模倣するためにそれをどうすればよいかわかりません。

検証コントロールが標準ウィンドウに配置されている場合、それらは機能します。OverrideMetadata 呼び出しを取り出すだけでも機能します (カスタム ウィンドウ内に残します)。OverrideMetadata 呼び出しをそのままにしておいても、カスタム ControlTemplate を定義しない場合にも機能します。テンプレートをデフォルトのままにしておくと、内部のものは検証イベントを適切に受け取り、検証テンプレートを使用します。

カスタム コントロール テンプレートを使用して、これらの検証エラー イベントを処理するためのストック機能を再び動作させるにはどうすればよいですか?

ありがとう!

4

1 に答える 1

0

次の ControlTemplate for Window は私にとってはうまくいきます:

<ControlTemplate TargetType="{x:Type Window}">
                <Grid Background="White">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="*" />
                    </Grid.RowDefinitions>
                    <AdornerDecorator>
                        <ContentPresenter Content="{TemplateBinding ContentControl.Content}" ContentTemplate="{TemplateBinding ContentControl.ContentTemplate}" ContentStringFormat="{TemplateBinding ContentControl.ContentStringFormat}" />
                    </AdornerDecorator>
                </Grid>
</ControlTemplate>

AdornerDecorator を削除すると、検証エラーは見えなくなります

于 2010-04-21T01:56:38.437 に答える