Guest User

Untitled

a guest
Nov 20th, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.42 KB | None | 0 0
  1. <CheckBox Content="CheckBox" Height="16" HorizontalAlignment="Left"
  2. Margin="176,132,0,0" Name="checkBox1" VerticalAlignment="Top"
  3. Command="{Binding YourCommand}" />
  4.  
  5. <CheckBox IsChecked="{Binding ServiceOrderItemTask.IsCompleted, Mode=TwoWay}" Content="{Binding ServiceOption.Name}">
  6.  
  7. <i:Interaction.Triggers>
  8. <i:EventTrigger EventName="Checked">
  9. <i:InvokeCommandAction Command="{Binding DataContext.IsCompletedCheckedCommand, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type t:RadGridView}}}" CommandParameter="{Binding}"/>
  10. </i:EventTrigger>
  11.  
  12. <i:EventTrigger EventName="Unchecked">
  13. <i:InvokeCommandAction Command="{Binding DataContext.IsCompletedUncheckedCommand, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type t:RadGridView}}}" CommandParameter="{Binding}"/>
  14. </i:EventTrigger>
  15. </i:Interaction.Triggers>
  16.  
  17. <CheckBox CommandParameter="{Binding}"
  18. Command="{Binding DataContext.AddRemovePresetAssignmentCommand,
  19. RelativeSource={RelativeSource FindAncestor,
  20. AncestorType={x:Type UserControl}}}"
  21. Content="{Binding Path=Name}">
  22.  
  23. <CheckBox HorizontalAlignment="Right"
  24. VerticalAlignment="Top"
  25. Margin="2,0,3,0"
  26. Command="{Binding CommandPinPropertyGrid}"
  27. CommandParameter="{Binding IsChecked, RelativeSource={RelativeSource Self}}">
  28. <CheckBox.Template>
  29. <ControlTemplate TargetType="{x:Type CheckBox}">
  30. <Grid>
  31. <Image x:Name="ImagePushpin" Width="16" Height="16" Source="pack://application:,,,/WpfUtil;component/Images/PushpinUnpinned16x16.png" />
  32. </Grid>
  33. <ControlTemplate.Triggers>
  34. <Trigger Property="IsChecked" Value="True">
  35. <Setter TargetName="ImagePushpin" Property="Source" Value="pack://application:,,,/WpfUtil;component/Images/PushpinPinned16x16.png" />
  36. </Trigger>
  37. </ControlTemplate.Triggers>
  38. </ControlTemplate>
  39. </CheckBox.Template>
  40. </CheckBox>
  41.  
  42. public MainWindowViewModel()
  43. {
  44. CommandPinPropertyGrid = new DelegateCommand<bool>(PinPropertyGrid);
  45.  
  46. // ******************************************************************
  47. public DelegateCommand<bool> CommandPinPropertyGrid { get; private set; }
  48.  
  49. public void PinPropertyGrid(bool pinned)
  50. {
  51. this.IsPropertyGridPinned = pinned;
  52. }
  53.  
  54. using System;
  55. using System.Windows.Input;
  56.  
  57. namespace HQ.Wpf.Util.Command
  58. {
  59.  
  60. /// <summary>
  61. /// Represents a command that forwards the <c>Execute</c> and <c>CanExecute</c> calls to specified delegates.
  62. /// </summary>
  63. public class DelegateCommand<T> : ICommand
  64. {
  65.  
  66. private readonly Action<T> _executeCallback;
  67. private readonly Predicate<T> _canExecuteCallback;
  68.  
  69. /////////////////////////////////////////////////////////////////////////////////////////////////////
  70. // OBJECT
  71. /////////////////////////////////////////////////////////////////////////////////////////////////////
  72.  
  73. /// <summary>
  74. /// Initializes a new instance of the <see cref="DelegateCommand<T>"/> class.
  75. /// </summary>
  76. /// <param name="executeCallback">The execute callback delegate.</param>
  77. public DelegateCommand(Action<T> executeCallback)
  78. : this(executeCallback, null)
  79. {
  80. // No-op
  81. }
  82.  
  83. /// <summary>
  84. /// Initializes a new instance of the <see cref="DelegateCommand<T>"/> class.
  85. /// </summary>
  86. /// <param name="executeCallback">The execute callback delegate.</param>
  87. /// <param name="canExecuteCallback">The can execute callback delegate.</param>
  88. public DelegateCommand(Action<T> executeCallback, Predicate<T> canExecuteCallback)
  89. {
  90. if (executeCallback == null)
  91. throw new ArgumentNullException("executeCallback");
  92.  
  93. this._executeCallback = executeCallback;
  94. this._canExecuteCallback = canExecuteCallback;
  95. }
  96.  
  97. /////////////////////////////////////////////////////////////////////////////////////////////////////
  98. // INTERFACE IMPLEMENTATION
  99. /////////////////////////////////////////////////////////////////////////////////////////////////////
  100.  
  101. #region ICommand Members
  102.  
  103. /// <summary>
  104. /// Defines the method that determines whether the command can execute in its current state.
  105. /// </summary>
  106. /// <param name="parameter">Data used by the command. If the command does not require data to be passed, this object can be set to <see langword="null"/>.</param>
  107. /// <returns>
  108. /// <c>true</c> if this command can be executed; otherwise, <c>false</c>.
  109. /// </returns>
  110. public bool CanExecute(object parameter)
  111. {
  112. return (this._canExecuteCallback == null) ? true : this._canExecuteCallback((T)parameter);
  113. }
  114.  
  115. /// <summary>
  116. /// Occurs when changes occur that affect whether or not the command should execute.
  117. /// </summary>
  118. public event EventHandler CanExecuteChanged
  119. {
  120. add
  121. {
  122. if (this._canExecuteCallback != null)
  123. CommandManager.RequerySuggested += value;
  124. }
  125. remove
  126. {
  127. if (this._canExecuteCallback != null)
  128. CommandManager.RequerySuggested -= value;
  129. }
  130. }
  131.  
  132. /// <summary>
  133. /// Defines the method to be called when the command is invoked.
  134. /// </summary>
  135. /// <param name="parameter">Data used by the command. If the command does not require data to be passed, this object can be set to <see langword="null"/>.</param>
  136. public void Execute(object parameter)
  137. {
  138. this._executeCallback((T)parameter);
  139. }
  140.  
  141. #endregion // ICommand Members
  142.  
  143. }
  144. }
  145.  
  146. CheckBox box = e.OriginalSource as CheckBox;
  147.  
  148. if(box.IsChecked.Value)
  149. DoThis();
  150. else
  151. DoAnotherMethod();
Add Comment
Please, Sign In to add comment