Vous pouvez trouver XCommand open source CodePlex projet WPF extention ici, xcommand.codeplex.com, ce qui vous permet de lier commande et CommandParameter de tout événement comme MouseMove, MouseLeftButtonDown à tous les éléments de l'interface utilisateur qui hérite de WPF UIElement.
Vous pouvez trouver Windows Store 8 application et fenêtres version de l'application de bureau des bibliothèques de classe ici. Vous voulez que WPFXCommand traite de l'application de bureau WPF. Ici, comment ça marche. Ajouter WPFXCommand.dll comme référence à votre projet de désir.
Ajouter l'espace de noms sur votre fichier XAML comme ci-dessous:
xmlns:XCmd="clr-namespace:WPFXCommand;assembly=WPFXCommand"
Maintenant, vous pouvez lier Commande et CommandParameter à des événements disponibles sur tous les éléments de l'interface utilisateur héritent de WPF UIElement comme ci-dessous:
<Grid>
<TextBlock Margin="20,30,20,0" VerticalAlignment="Top" Height="80" x:Name="XTextBlock"
Foreground="{Binding FgColor, Mode=TwoWay}"
XCmd:MouseMove.Command="{Binding TextBlockPointerMovedCommand}"
XCmd:MouseLeftButtonDown.Command="{Binding TextBlockPointerPressedCommand}"
XCmd:MouseLeave.Command="{Binding TextBlockPointerExitedCommand}"
Text="{Binding Description, Mode=TwoWay}">
</TextBlock>
<Grid Grid.Column="1" Background="{Binding BgColor, Mode=TwoWay}"
XCmd:MouseMove.Command="{Binding GridPointerMovedCommand}"
XCmd:MouseMove.CommandParameter="{Binding ElementName=XTextBlock, Path=Text}"
XCmd:MouseLeftButtonDown.Command="{Binding GridPointerPressedCommand}"
XCmd:MouseLeftButtonDown.CommandParameter="{Binding ElementName=XTextBlock, Path=Text}"
>
</Grid>
</Grid>
Espérons que cela vous aidera à se débarrasser de l'e vent basé code derrière.
Vous avez oublié de mentionner que cela utilise le mélange – TigOldBitties