Custom Panel

  • Thread starter Thread starter Vivien Parlat
  • Start date Start date
V

Vivien Parlat

Hello,

I'm trying to create a custom panel in WPF, which would act like a
WrapPanel but with a "NewLine" option. So I'm trying to create kinda
"StackPanel" which would host WrapPanels.

Tutorials on custom Panels over the internet talk a lot about creating
a new Panel from scratch, overriding MeasureOverride and
ArrangeOverride. However, all that i want to do is to "route" any new
UIElement to the current row's WrapPanel.

The goal is, finally, to display this as:
<myPanel>
<Item1>
<Item2>
<NewLine>
<Item3>
</myPanel>

which would be internally stored as:
<StackPanel>
<WrapPanel>
<Item1>
<Item2>
</WrapPanel>
<WrapPanel>
<Item3>
</WrapPanel>
</StackPanel>

I can't figure out how to do. I tried to override ArrangeOverride but
have problems with Child and visual tree. Is there an easy way to do
this ?

Thanks in advance...
 
Vivien Parlat said:
Hello,

I'm trying to create a custom panel in WPF, which would act like a
WrapPanel but with a "NewLine" option. So I'm trying to create kinda
"StackPanel" which would host WrapPanels.

Tutorials on custom Panels over the internet talk a lot about creating
a new Panel from scratch, overriding MeasureOverride and
ArrangeOverride. However, all that i want to do is to "route" any new
UIElement to the current row's WrapPanel.

The goal is, finally, to display this as:
<myPanel>
<Item1>
<Item2>
<NewLine>
<Item3>
</myPanel>

which would be internally stored as:
<StackPanel>
<WrapPanel>
<Item1>
<Item2>
</WrapPanel>
<WrapPanel>
<Item3>
</WrapPanel>
</StackPanel>

I can't figure out how to do. I tried to override ArrangeOverride but
have problems with Child and visual tree. Is there an easy way to do
this ?

Just an idea - why not derive your panel from WrapPanel and define an
attached property such as MyPanel.NewLineAfter? Then you could take the
existing WrapPanel MesaureOverride and ArrangeOverride methods (using
Reflector to get them) and adapt them to take account of children with
NewLineAfter set to True. This might be simpler than having to mess about
with changing the children of your control. The XAML would then look like:
<myPanel>
<Item1>
<Item2 MyPanel.NewLineAfter=True">
<Item3>
</myPanel>

Chris Jobson
 
Back
Top