michael
michael

Reputation: 15282

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.

Upvotes: 0

Views: 1051

Answers (2)

treehouse
treehouse

Reputation: 2531

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.

Upvotes: 0

Rick Sladkey
Rick Sladkey

Reputation: 34240

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.

Upvotes: 2

Related Questions