this C# code을 번역하려고합니다. 지금까지 내 시도 :F의 사용자 지정 라우팅 이벤트 #
type MyButtonSimple() as self =
inherit Button()
static let TapEvent =
EventManager.RegisterRoutedEvent
("Tap", RoutingStrategy.Bubble,
typeof<RoutedEventHandler>, typeof<MyButtonSimple>)
let tapEvent = new Event<RoutedEventHandler, RoutedEventArgs>()
let raiseTapEvent() =
let newEventArgs = new RoutedEventArgs(TapEvent)
tapEvent.Trigger(self, newEventArgs)
[<CLIEvent>]
member x.Tap = tapEvent.Publish
// For demonstration purposes we raise the event when clicked
override self.OnClick() =
raiseTapEvent()
MainWindow.xaml 애니메이션을 시작되지 않습니다 버튼을 클릭
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:funk="clr-namespace:funk;assembly=appWPF"
Title="Routed" Height="300" Width="400">
<StackPanel Background="LightGray">
<funk:MyButtonSimple Content="Spin" Background="#808080" Foreground="LightGray">
<funk:MyButtonSimple.RenderTransform>
<TransformGroup>
<RotateTransform x:Name="rotate"/>
</TransformGroup>
</funk:MyButtonSimple.RenderTransform>
<funk:MyButtonSimple.Triggers>
<EventTrigger RoutedEvent="funk:MyButtonSimple.Tap">
<BeginStoryboard>
<Storyboard RepeatBehavior="Forever">
<DoubleAnimation
Storyboard.TargetName="rotate"
Storyboard.TargetProperty="Angle"
From="0" To="90" Duration="0:0:2"/>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</funk:MyButtonSimple.Triggers>
</funk:MyButtonSimple>
</StackPanel>
</Window>
.
코드 RoutedEvent="funk:MyButtonSimple.Tap"
을 RoutedEvent="GotFocus"
으로 변경하면 작동 예제 (Button.Click이 무시됨)가됩니다.
내가 잘못하고있는 아이디어가 있습니까?
간단히''을 쓰려고 했습니까? –
@Filippo 예. 작동하지 않습니다. FrameworkElement 또는 UIElement에서 상속되지 않은 이벤트는 지정해야합니다. Button.Click. – Funk
'static member'를'static let '으로 바꾸어보세요. –