0

Does setting a Framework elements (Border in this case) width in XAML prevent me from changing this value at run time?

I have a grid containing a border which in turn contains some other controls. I have an animation which expands the grid and border width and height increasing the values from 0.

I have then placed a button above the border to act as a re-sizing aid (it is a border-less window). here is a snippet of the code that should be re-sizing the border:

private void GridResize_Click(object sender, RoutedEventArgs e) { startPoint = this.PointToScreen(Mouse.GetPosition(this)); Mouse.Capture(GridResize); Resizing = true; } private void Window_MouseMove(object sender, MouseEventArgs e) { if (Resizing) { FrameworkElement border = (FrameworkElement)LibraryBorder; //an arbitrary value for testing border.Width += 20; LibraryBorder.InvalidateVisual(); } } 

The initial animation sets the borders width to 1500. When debugging both events are being registered and Window_MouseMove is trying to amend the borders width. It does not however alter the value - it remains at 1500. I cast the element to a FrameworkElement in the hope that this would allow me to amend the width property. I assume that my xaml values are somehow overriding my code. Any ideas on how to get around this. I thought I would ask before I go the route of moving all my animations in to code to discover there is a better way ( or that the code approach wont make a difference!!).

Thanks in advance for any answers

5
  • 1
    Does your Storyboard have FillBehavior HoldEnd which is default? This would prevent you from changing the width. See Dependency Property Value Precedence. Commented May 19, 2013 at 8:49
  • I haven't set these and weren't aware that they were defaults. I will have a look - thanks for the pointer Commented May 19, 2013 at 8:51
  • If I set FillBehavior to Stop then the animation runs and the values revert back to their original state. Is there a way to release the HoldEnd from code? Commented May 19, 2013 at 8:55
  • Thanks to LPL - if you put your suggestion as an answer I will accept. It seems need to set my FillBehavior to Stop and then handle the onCompleted event for my double animation that deals with the width property - setting this to the final value and opening the property for editing again. Commented May 19, 2013 at 9:05
  • I've added my comment as an answer. Thanks. Glad I could help. Commented May 19, 2013 at 9:31

1 Answer 1

2

Make sure your Storyboard doesn't have FillBehavior HoldEnd which is default. This would prevent you from changing the width. See Dependency Property Value Precedence.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.