Search code examples
wpfxamlpanelviewboxarrangeoverride

wpf custom panel


I'm looking at creating a panel that takes all the children and wraps them inside of a ViewBox so it can scale them down to a certain uniform size.

I'm not sure if this is even possible to do, but I thought I'd ask. The reason why I'm not sure if this is possible is because Panel's don't have any xaml associated to them. They measure and arrange children in code. Any tips?


After not being clear enough, I figure I'll be more specific:

I want a Panel because I want to arrange and measure my children.

  1. The measure find the AVERAGE height/width of all the children elements.
  2. The arrange puts them into a grid-like pattern and scales them to the average height/width. I don't want them cliptobounds, I want them scaled up or scaled down appropriately.

I already got the measureoverride function working to find the average height/width, but I can't figure out how to scale them in my arrangeoverride.


Solution

  • You haven't completely specified how you want your panel to work so I can't give you a sample panel, but I can point you to a working panel that does something similar to what you want to do:

    In the example you can see that we can simulate a Viewbox by just scaling the children of the panel ourselves. As I mentioned, exactly how you want to scale them is up to you.