Guest User

Untitled

a guest
Jul 18th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.28 KB | None | 0 0
  1. <VisualState x:Name="Expanded">
  2. <Storyboard>
  3. <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Width)" Storyboard.TargetName="JobMaster">
  4. <EasingDoubleKeyFrame KeyTime="0">
  5. <EasingDoubleKeyFrame.Value>
  6. <Binding
  7. Path="ActualWidth"
  8. RelativeSource="{RelativeSource FindAncestor, AncestorType={x:Type WrapPanel}}" />
  9. </EasingDoubleKeyFrame.Value>
  10. </EasingDoubleKeyFrame>
  11. </DoubleAnimationUsingKeyFrames>
  12. </Storyboard>
  13.  
  14. <VisualState x:Name="Expanded">
  15. <Storyboard>
  16. <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Width)" Storyboard.TargetName="JobMaster">
  17. <EasingDoubleKeyFrame KeyTime="0" Value="800" />
  18. </DoubleAnimationUsingKeyFrames>
  19. </Storyboard>
  20.  
  21. <UserControl.Width>
  22. <Binding
  23. Path="ActualWidth"
  24. RelativeSource="{RelativeSource AncestorType={x:Type WrapPanel}}" />
  25. </UserControl.Width>
  26.  
  27. <Binding Path="ActualWidth" ElementName="MyWrapPanel"/>
  28.  
  29. public class TileExpandColapseBehavoir : Behavior<Control>
  30. {
  31. private ITile _data;
  32.  
  33. #region Properties
  34.  
  35. public static readonly DependencyProperty TileControlProperty = DependencyProperty.Register("TileControl", typeof(object), typeof(TileExpandColapseBehavoir), new PropertyMetadata(null));
  36. public static readonly DependencyProperty DefaultWidthProperty = DependencyProperty.Register("DefaultWidth", typeof(Double), typeof(TileExpandColapseBehavoir), new PropertyMetadata(null));
  37.  
  38. public object TileControl
  39. {
  40. get { return (object)this.GetValue(TileControlProperty); }
  41. set { this.SetValue(TileControlProperty, value); }
  42. }
  43.  
  44. public double DefaultWidth
  45. {
  46. get { return (double)this.GetValue(DefaultWidthProperty); }
  47. set { this.SetValue(DefaultWidthProperty, value); }
  48. }
  49.  
  50. #endregion
  51.  
  52. public TileExpandColapseBehavoir()
  53. {
  54. }
  55.  
  56. protected override void OnAttached()
  57. {
  58. this.AssociatedObject.PreviewMouseDown +=new MouseButtonEventHandler(AssociatedObject_MouseUp);
  59. }
  60.  
  61. private void AssociatedObject_MouseUp(object sender, MouseButtonEventArgs e)
  62. {
  63. UIElement child = (UIElement)sender;
  64. WrapPanel parentWrap = FindAncestorUtil.TryFindAcestor<WrapPanel>(child);
  65. if (parentWrap != null && TileControl is UserControl)
  66. {
  67. GetData();
  68. if (_data.IsExpanded == false)
  69. {
  70. Binding newBinding = new Binding();
  71. newBinding.Source = parentWrap;
  72. newBinding.Path = new PropertyPath("ActualWidth");
  73.  
  74. UserControl thisTile = (UserControl)TileControl;
  75. BindingOperations.SetBinding(thisTile, UserControl.WidthProperty, newBinding);
  76. _data.IsExpanded = true;
  77. }
  78. else
  79. {
  80. UserControl thisTile = (UserControl)TileControl;
  81.  
  82. BindingOperations.ClearBinding(thisTile, UserControl.WidthProperty);
  83. thisTile.Width = DefaultWidth;
  84. _data.IsExpanded = false;
  85. }
  86. }
  87. }
  88.  
  89. private void GetData()
  90. {
  91. if (_data == null && AssociatedObject.DataContext is ITile)
  92. {
  93. _data = (ITile)AssociatedObject.DataContext;
  94. }
  95. }
  96. }
Add Comment
Please, Sign In to add comment