已答覆 KeyTrigger的複合鍵

  • 2011年7月19日 上午 05:07
     
      包含代碼

    我使用Blend做鍵盤的event接收

    <i:Interaction.Triggers>
     <ei:KeyTrigger Key="Esc">
      <ei:CallMethodAction TargetObject="{Binding ElementName=qq}" MethodName="MVVM_QQ"/>
     </ei:KeyTrigger>
    </i:Interaction.Triggers>
    


    但是我有一個這種快捷建的需求是要Ctrl+Shift+X的鍵盤事件

    但是Blend提供的KeyTrigger卻只能收Ctrl或是Shift

    有沒有可以收三個的這種功能

    謝謝

所有回覆

  • 2011年7月19日 上午 06:04
     
      包含代碼

    您好,

    KeyTrigger可以做到這個功能,只要您在Modifiers屬性中設置ctrl跟shift這兩個按鍵,然後在Key屬性設定成x就可以完成Ctrl+Shift+X

    <i:Interaction.Triggers>
      <ei:KeyTrigger Key="x" Modifiers="Control,Shift" >	
        <ei:CallMethodAction TargetObject="{Binding ElementName=qq}" MethodName="MVVM_QQ"/>
      </ei:KeyTrigger>
    </i:Interaction.Triggers>
    

     


  • 2011年7月19日 上午 07:44
     
     

    還是不行阿,在Blend裡面就會有錯誤顯示了

    強制去run,程式也會當掉在<ei:KeyTrigger Key="x" Modifiers="Control,Shift" >
    上面

    而且Blend上面的 Modifiers是單選的功能已

  • 2011年7月19日 上午 08:36
     
      包含代碼

    您好,

    我實際在我的Blend 4中測試是可以執行的,我貼一下我測試時的code,這裡我是按下組合鍵後改變背景顏色

    另外您說會有錯誤顯示可以說一下顯示錯誤的資訊嗎?

    <Grid x:Name="LayoutRoot" Background="White">
    		<i:Interaction.Triggers>
    			<ei:KeyTrigger Key="x" Modifiers="Control,Shift" >
    				<ei:ChangePropertyAction PropertyName="Background" TargetName="LayoutRoot">
    					<ei:ChangePropertyAction.Value>
    						<SolidColorBrush Color="#FFDC6767"/>
    					</ei:ChangePropertyAction.Value>
    				</ei:ChangePropertyAction>
    			</ei:KeyTrigger>
    		</i:Interaction.Triggers>
    </Grid>
    


  • 2011年7月19日 下午 01:51
     
     

    我你給的程式貼到Xaml以後

    在blend的錯誤訊息裡面出現

    無法識別的Modifers="Control,Shift"

  • 2011年7月22日 上午 09:14
     
     

    您好,

    不知道您使用的Blend及Silverlight版本分別是多少?

    我測試時使用的是Silverlight 4專案然後搭配Blend 4


  • 2011年7月22日 上午 10:47
     
     
    我是用WPF+.NET4的專案
  • 2011年7月23日 上午 05:58
     
     已答覆 包含代碼

    您好,

    如果是WPF專案的話,Modifers屬性可以改成用+號來連結就可以完成Ctrl+Shift+X的需求了

    <i:Interaction.Triggers>
    			<ei:KeyTrigger Modifiers="Control+Shift" Key="X">
    				<ei:ChangePropertyAction PropertyName="Background">
    					<ei:ChangePropertyAction.Value>
    						<SolidColorBrush Color="#FFAB3636"/>
    					</ei:ChangePropertyAction.Value>
    				</ei:ChangePropertyAction>
    			</ei:KeyTrigger>
    </i:Interaction.Triggers>
    


    • 已標示為解答 oven425 2011年7月24日 下午 01:00
    •