1. 程式人生 > >C#自定義窗體style中 button點選事件通過Command傳遞

C#自定義窗體style中 button點選事件通過Command傳遞

資源字典中

<

Button x:Name="BtnClose" Margin="0,-1.5,-1,0" Style="{DynamicResource ButtonClose}"
              HorizontalAlignment="Right" VerticalAlignment="Top" Command="ApplicationCommands.Close" />  //點選觸發close命令

主窗體中

<Window.CommandBindings>
        <CommandBinding Command="Close" Executed="ClosedBtn_Click"/> //觸發命令後執行ClosedBtn_Click事件
        <CommandBinding Command="New" Executed="Minimize_Executed"/>
</Window.CommandBindings>


<Window.Triggers>
    <EventTrigger SourceName="cmdStart" RoutedEvent="Button.Click">
        <BeginStoryboard Name="fadeStoryboardBegin">
            
        </BeginStoryboard>
    </EventTrigger>
</Window.Triggers>