0

私が持っているのはカスタムウィンドウです。bool 依存関係プロパティが追加されました。この依存関係プロパティをトリガーの条件として使用したいと考えています。いわば私のトリガーを回避する方法。残念ながら、適切な非 null 値の例外がスローされています。これで頭をぶつけます。また、トリガーにバインドする前に、依存関係プロパティもテストしました。依存関係プロパティ ラッパーにヒットすることはありません。私がそれをしたときにエラーがスローされたり表示されたりすることはありません。

DependencyProperty のセットアップ:

    /// <summary>
    /// The override visibility property
    /// </summary>
    public static readonly DependencyProperty OverrideVisibilityProperty = DependencyProperty.Register(
        "OverrideVisibility", typeof(bool), typeof(MyWindow), new PropertyMetadata(false));

    /// <summary>
    /// Gets or sets the override visibility.
    /// </summary>
    /// <value>The override visibility.</value>
    public bool OverrideVisibility
    {
        get
        {
            return (bool)this.GetValue(OverrideVisibilityProperty);
        }

        set
        {
            this.SetValue(OverrideVisibilityProperty, value);
        }
    }

スタイリッシュなトリガー設定

               <ControlTemplate.Triggers>
                    <MultiTrigger>
                        <MultiTrigger.Conditions>
                            <Condition Property="WindowStyle" Value="None" />
                            <Condition Binding="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=OverrideVisibility}" Value="false" />  
                        </MultiTrigger.Conditions>
                        <MultiTrigger.Setters>
                            <Setter TargetName="WindowCloseButton" Property="Visibility" Value="Visible" />
                        </MultiTrigger.Setters>
                    </MultiTrigger>
               </ControlTemplate.Triggers>

フォーム xaml のセットアップ:

<local:MyWindow x:Class="MyForm"
                    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    Width="500"
                    Height="500"
                    OverrideVisibility="True">
4

1 に答える 1

1

あなたのエラーはこの行にあります:

<Condition Binding="{Binding RelativeSource={RelativeSource FindAncestor, 
    AncestorType={x:Type Window}}, Path=OverrideVisibility}" Value="false" />  

具体的には、これはあなたのエラーです:

AncestorType={x:Type Window}

Visual Studio の出力ウィンドウに次のようなエラーが表示される可能性があります。

Error: No OverrideVisibility property found on object Window

その代わりに、カスタムBindingの名前/タイプを使用します...次のようなもの: Window

AncestorType={x:Type YourPrefix:YourCustomWindow}

さらに、あなたはこう言いました。

依存関係プロパティ ラッパーにヒットすることはありません

そうではありません...それらはあなたの使用のためだけです...フレームワークでは使用されません。を通過する値を監視する場合は、イベント ハンドラーDependencyPropertyを登録する必要があります。PropertyChangedCallback詳細については、MSDN のカスタム依存関係プロパティページを参照してください。


更新 >>>

あ、コメント見て気づきました。あなたStyleとあなたのビューの両方がアクセスできるアセンブリで添付プロパティを宣言できる場合は、まだそれを行うことができます。その可能性がある場合は、MSDN の添付プロパティの概要ページを参照して、その方法を確認してください。

最後に、次のように添付プロパティにバインドできます。

<animation Storyboard.TargetProperty="(ownerType.propertyName)" .../>

この例は、MSDN のProperty Path Syntaxページからのものです。

于 2014-03-25T23:08:54.690 に答える