我正在創建一個自定義控件(它只是一個從網格派生的自定義網格,我想保持它爲一個網格,因爲我還有其他一些東西想嘗試一下),我的問題是,爲什麼沒有當我試圖從一個EventTrigger觸發它的故事板的工作,但一個正常的觸發下工作正常,我的代碼如下:WPF自定義控件EventTrigger不燒或動畫不工作
<Style TargetType="{x:Type local:GridEx}">
<Setter Property="Width" Value="100" />
<Setter Property="Height" Value="100" />
<Style.Triggers>
<EventTrigger RoutedEvent="MouseRightButtonDown">
<BeginStoryboard>
<Storyboard >
<DoubleAnimation Storyboard.TargetProperty="Width" To="300" Duration="0:0:1" FillBehavior="HoldEnd" />
<DoubleAnimation Storyboard.TargetProperty="Height" To="300" Duration="0:0:1" FillBehavior="HoldEnd" />
</Storyboard>
</BeginStoryboard>
</EventTrigger>
<Trigger Property="IsMouseOver" Value="True" >
<!--<Trigger.EnterActions>
<BeginStoryboard>
<Storyboard >
<DoubleAnimation Storyboard.TargetProperty="Width" To="300" Duration="0:0:1" FillBehavior="HoldEnd" />
<DoubleAnimation Storyboard.TargetProperty="Height" To="300" Duration="0:0:1" FillBehavior="HoldEnd" />
</Storyboard>
</BeginStoryboard>
</Trigger.EnterActions>
<Trigger.ExitActions>
<BeginStoryboard>
<Storyboard >
<DoubleAnimation Storyboard.TargetProperty="Width" To="100" Duration="0:0:1" FillBehavior="HoldEnd" />
<DoubleAnimation Storyboard.TargetProperty="Height" To="100" Duration="0:0:1" FillBehavior="HoldEnd" />
</Storyboard>
</BeginStoryboard>
</Trigger.ExitActions>-->
<Setter Property="Effect" Value="{StaticResource LiftEffect}"/>
<Setter Property="RenderTransform">
<Setter.Value>
<TranslateTransform X="-1" Y="-1" />
</Setter.Value>
</Setter>
<Setter Property="Panel.ZIndex" Value="10" />
</Trigger>
</Style.Triggers>
</Style>
這個想法是很很簡單,當用戶按住鼠標右鍵時,我只想讓網格的大小增加。我知道動畫的作品,因爲如果我從觸發器「IsMouseOver」開始,它工作正常,但如果我按住鼠標沒有任何反應?
並沒有它的評論問題:P
我的自定義控件派生自網格。
編輯代碼使用System.Windows ADDED
; using System.Windows.Controls;
namespace WPFCCLIB
{
public class GridEx : Grid
{
public static readonly RoutedEvent LeftMouseDoubleClickEvent = EventManager.RegisterRoutedEvent("LeftMouseDoubleClick",RoutingStrategy.Bubble,typeof(RoutedEventHandler), typeof(GridEx));
public event RoutedEventHandler LeftMouseDoubleClick
{
add { AddHandler(LeftMouseDoubleClickEvent, value); }
remove { RemoveHandler(LeftMouseDoubleClickEvent, value); }
}
static GridEx()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(GridEx), new FrameworkPropertyMetadata(typeof(GridEx)));
}
void RaiseLeftMouseDoubleClickEvent()
{
RoutedEventArgs newEventArgs = new RoutedEventArgs(GridEx.LeftMouseDoubleClickEvent);
RaiseEvent(newEventArgs);
}
}
}
動畫工作正常標準的'Grid'是有什麼在你的派生電網與該鼠標事件interferring?你嘗試過'RoutedEvent =「Grid.MouseRightButtonDown」'? –
據我所知不,可能會干擾我沒有明確添加任何內容:/但對於它在正常風格的網格中工作,我已經看到它的工作,這可能是爲什麼我有點困惑至於爲什麼它突然不起作用。 – Heinrich
我剛剛設置了派生網格,並且動畫在那裏也能正常工作,您是否可以發佈衍生網格中的代碼,它是否有自己的模板? –