0

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.

michael
  • 14,844
  • 28
  • 89
  • 177
  • 1
    are you sure you want to have a panel? As you said a panel measures and arranges. What you describe sounds more like an ItemsControl whoose ItemsContainer is a ViewBox... otherwise give us some more information of how you imagine that panels children being arranged. Alternatively, if I read your question slightly different what you need is a ViewBox with a Grid (or any other Panel) inside that takes the children. Please be more specific – Markus Hütter Apr 20 '11 at 20:31
  • you said you already got the measure function working. would you please be so kind to show us what you got so far for your panel, then maybe we can better realize what exactly you want. At the moment it doesn't seem like you put too much thought into it. Maybe you could provide us with a specific example. – Markus Hütter Apr 22 '11 at 10:38

2 Answers2

2

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.

Community
  • 1
  • 1
Rick Sladkey
  • 33,988
  • 6
  • 71
  • 95
0

Even after your update, I agree with Markus. It doesn't seem you need a custom panel. What you need is an ItemsControl with UniformGrid as ItemsPanel and ViewBox as ItemsContainer. UniformGrid decides how your items container are arranged. ViewBox handles stretch and scale of each item.

treehouse
  • 2,521
  • 1
  • 21
  • 39
  • 1
    A UniformGrid does not make everything uniform to the _average_ size, therefore I need a custompanel. I thought about a UniformGrid but I'm trying to scale everything to be based on the _average_ size. – michael Apr 21 '11 at 13:49