ビューモデルのプロパティが変更されたときにアニメーション(スケール)を実行するカスタムStackPanelを作成しようとしています。私は私が私の派生クラスで私のテストウィンドウでwpfカスタムスタックパネルdatatrigger
public partial class TrgScaleStackPanel : StackPanel
{
#region TriggerValue DP
/// <summary>
/// Gets or sets the Value which is being displayed
/// </summary>
public bool TriggerValue
{
get { return (bool)GetValue(TriggerValueProperty); }
set { SetValue(TriggerValueProperty, value); }
}
/// <summary>
/// Identified the Label dependency property
/// </summary>
public static readonly DependencyProperty TriggerValueProperty =
DependencyProperty.Register("TriggerValue", typeof(bool),
typeof(TrgScaleStackPanel), new PropertyMetadata(false));
#endregion
public TrgScaleStackPanel()
{
InitializeComponent();
}
}
依存関係プロパティにバインド私はDataTriggerとスタイルを追加したXAMLで
<StackPanel x:Class="StackPanelDemo.TrgScaleStackPanel"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
x:Name="TrgScaleParent"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<StackPanel.Style>
<Style TargetType="{x:Type StackPanel}" >
<Style.Triggers>
<DataTrigger Binding="{Binding ElementName=TrgScaleParent.TriggerValue}" Value="True">
<DataTrigger.EnterActions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Duration="0:0:0.25" To="1" Storyboard.TargetProperty="(LayoutTransform).(ScaleTransform.ScaleY)"/>
</Storyboard>
</BeginStoryboard>
</DataTrigger.EnterActions>
<DataTrigger.ExitActions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Duration="0:0:0.25" To="0" Storyboard.TargetProperty="(LayoutTransform).(ScaleTransform.ScaleY)"/>
</Storyboard>
</BeginStoryboard>
</DataTrigger.ExitActions>
</DataTrigger>
</Style.Triggers>
</Style>
</StackPanel.Style>
を依存関係プロパティを作成しましたhave
<stackPanelDemo:TrgScaleStackPanel TriggerValue="{Binding SettingsViewVisible}">
<TextBlock>Hello</TextBlock>
<Button>Goodbye</Button>
<stackPanelDemo:TrgScaleStackPanel.LayoutTransform>
<ScaleTransform ScaleX="1" ScaleY="0" />
</stackPanelDemo:TrgScaleStackPanel.LayoutTransform>
</stackPanelDemo:TrgScaleStackPanel>
これはビルドされて実行されますが、残念なことにトリガーは起動しません。私はそれがデータのコンテキストと関係があるとは思うが、本当にわからない。
誰かが私はずっと私は残念ながら、私は本当に、設定のStackPanelを作成するには更に多く持っている
<DataTrigger Binding="{Binding Path=TriggerValue, RelativeSource={RelativeSource Self}}" Value="True">
を使用するために必要なことを発見いじった後、間違った
依存プロパティへのコールバックを追加しましたが、「値」は変更されていますが、トリガは起動していません。 –