Showing posts with label MeasureOverride. Show all posts
Showing posts with label MeasureOverride. Show all posts

Thursday, March 21, 2013

XamlParse Exception for that darn FrameworkElement MeasureOverride

I just wrangled with that fun and oh so detailed error of the XamlParseException that tells you something is wrong with your FrameworkElement MeasureOverride.

After hitting my head on my desk, cursing in my mind (cubicles aren't very private) and wanting to chuck my computer through the window, I figured it out.

This probably won't work for everyone, but it could be a good starting point. In my codebehind I had a SizeChanged declared.


public myControl()
{
    InitializeComponent();
    this.SizeChanged += new SizeChangedEventHandler(myControl_SizeChanger);
}

Once I commented out (and then got rid of) the size changed event, the error went away.

to get the autosizing I wanted on this control, in the main "header" (that's what I call the code at the top that declares all of the xmlns values), I set a DESIGN height and width instead of simply stating Height and Width :

Example:

<UserControl x:Class="application.myClass"
                     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                     mc:Ignorable="d"  d:DesignHeight="100" d:DesignWidth="100">

.... rest of code here
</UserControl>

Tuesday, March 5, 2013

More resizing "fun"

Turns out that the project I am currently on has controls with a SizeChanged event already coded into them. 

Our developer noticed this when the app kept refreshing layout over and over and over and over again. So, the solution for these pages was to use MeasureOverride

protected override Size MeasureOverride(Size availableSize)
{
     this.LayoutRoot.Height = availableSize.Height;
     this.LayoutRoot.Width = availableSize.Width;
     return base.MeasureOverride(availablesSize);
}

Here is a link with some more information on how this operates. Luckily - I didn't need to have any other code with this one on those pages.