2013-04-24 121 views
0

我的WPF應用程序中有一個TextBlock控制。當用戶按住shift鍵並右鍵雙擊時,我想顯示一個「復活節彩蛋」。顯示對話框

我添加了一個RoutedUiCommand在我的應用程序中的靜態類,我已經定義了所有的命令。我添加了一個命令爲我的新命令綁定:

<UserControl.CommandBindings> 
    <CommandBinding CanExecute="ShowDiagnostics_CanExecute" Command="cs:CarSystemCommands.ShowDiagnostics" Executed="ShowDiagnostics_Executed" /> 
</UserControl.CommandBindings> 

當我創建的RoutedUiCommand,我指定的RightDoubleClick一個MouseGestureShift一個ModifierKey。到現在爲止還挺好。

如何與TextBlock命令相關聯?

回答

0

我最終什麼事做是對CommandBindingUserControl.ResourcesTextBlock移動:

<TextBlock ...> 
    <TextBlock.CommandBindings> 
     <CommandBinding CanExecute="ShowDiagnostics_CanExecute" Command="cs:CarSystemCommands.ShowDiagnostics" Executed="ShowDiagnostics_Executed" /> 
    </TextBlock.CommandBindings> 
</TextBlock> 

現在,什麼都不會發生,直到你持有向下TextBlock shift鍵&右側雙擊。

我給其他的答案了投票,因爲他們會工作,太。

1

如何把一個InputBinding文本塊,將調用命令嗎?