Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <VisualState x:Name="Expanded">
- <Storyboard>
- <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Width)" Storyboard.TargetName="JobMaster">
- <EasingDoubleKeyFrame KeyTime="0">
- <EasingDoubleKeyFrame.Value>
- <Binding
- Path="ActualWidth"
- RelativeSource="{RelativeSource FindAncestor, AncestorType={x:Type WrapPanel}}" />
- </EasingDoubleKeyFrame.Value>
- </EasingDoubleKeyFrame>
- </DoubleAnimationUsingKeyFrames>
- </Storyboard>
- <VisualState x:Name="Expanded">
- <Storyboard>
- <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Width)" Storyboard.TargetName="JobMaster">
- <EasingDoubleKeyFrame KeyTime="0" Value="800" />
- </DoubleAnimationUsingKeyFrames>
- </Storyboard>
- <UserControl.Width>
- <Binding
- Path="ActualWidth"
- RelativeSource="{RelativeSource AncestorType={x:Type WrapPanel}}" />
- </UserControl.Width>
- <Binding Path="ActualWidth" ElementName="MyWrapPanel"/>
- public class TileExpandColapseBehavoir : Behavior<Control>
- {
- private ITile _data;
- #region Properties
- public static readonly DependencyProperty TileControlProperty = DependencyProperty.Register("TileControl", typeof(object), typeof(TileExpandColapseBehavoir), new PropertyMetadata(null));
- public static readonly DependencyProperty DefaultWidthProperty = DependencyProperty.Register("DefaultWidth", typeof(Double), typeof(TileExpandColapseBehavoir), new PropertyMetadata(null));
- public object TileControl
- {
- get { return (object)this.GetValue(TileControlProperty); }
- set { this.SetValue(TileControlProperty, value); }
- }
- public double DefaultWidth
- {
- get { return (double)this.GetValue(DefaultWidthProperty); }
- set { this.SetValue(DefaultWidthProperty, value); }
- }
- #endregion
- public TileExpandColapseBehavoir()
- {
- }
- protected override void OnAttached()
- {
- this.AssociatedObject.PreviewMouseDown +=new MouseButtonEventHandler(AssociatedObject_MouseUp);
- }
- private void AssociatedObject_MouseUp(object sender, MouseButtonEventArgs e)
- {
- UIElement child = (UIElement)sender;
- WrapPanel parentWrap = FindAncestorUtil.TryFindAcestor<WrapPanel>(child);
- if (parentWrap != null && TileControl is UserControl)
- {
- GetData();
- if (_data.IsExpanded == false)
- {
- Binding newBinding = new Binding();
- newBinding.Source = parentWrap;
- newBinding.Path = new PropertyPath("ActualWidth");
- UserControl thisTile = (UserControl)TileControl;
- BindingOperations.SetBinding(thisTile, UserControl.WidthProperty, newBinding);
- _data.IsExpanded = true;
- }
- else
- {
- UserControl thisTile = (UserControl)TileControl;
- BindingOperations.ClearBinding(thisTile, UserControl.WidthProperty);
- thisTile.Width = DefaultWidth;
- _data.IsExpanded = false;
- }
- }
- }
- private void GetData()
- {
- if (_data == null && AssociatedObject.DataContext is ITile)
- {
- _data = (ITile)AssociatedObject.DataContext;
- }
- }
- }
Add Comment
Please, Sign In to add comment