Using control that inherits from Panel instead of ContentControl

Aug 31, 2010 at 5:45 PM

Does Caliburn micro have anything built-in to deal with using a control that inherits from System.Windows.Controls.Panel instead of using a ContentControl? My view needs to be added to the Children collection property. I can't use a ContentControl because I am using a third party control for layout and it inherits from System.Windows.Controls.Panel. I tried the ContentControl but it throws the scaling/rendering off for my third party control.

Coordinator
Aug 31, 2010 at 7:09 PM

Have you tried using an ItemsControl with a custom panel template? That is the preferred approach..one which I have used many times.

Aug 31, 2010 at 7:45 PM
Edited Aug 31, 2010 at 7:48 PM

Thanks for the quick reply but as I was trying what you mentioned I realized that I can override the ContentControl control template, duh! Sometimes I get so caught up with the code that I forget that the visual rendering of a control can be overriden Anyway I just applied my custom style and everything works great. I have to thank you for sharing this awesome framework with the community. You have saved me countless hours of doing mundane "plumbing" code.

Aug 31, 2010 at 8:04 PM
Edited Aug 31, 2010 at 8:15 PM

Roberto, you can see an example of this in the ManyViewModels sample: http://codeswamp.com/wp-content/uploads/2010/08/Caliburn.Micro-devLink-talk.zip 

In that sample the View has
...

    <ItemsControl x:Name="Tiles">
        <ItemsControl.ItemsPanel>
            <ItemsPanelTemplate>
                <WrapPanel>
                </WrapPanel>
            </ItemsPanelTemplate>
        </ItemsControl.ItemsPanel>
    </ItemsControl>
...

and the ViewModel has 
...
public BindableCollection<SimpleTileViewModel> Tiles { get; private set;}
...

Does this fit what you're needing?

Aug 31, 2010 at 8:34 PM
Edited Sep 1, 2010 at 12:54 AM

Well, yes but I realized that it could be done without having to use an ItemsControl. It is a single view that I needed and the problem was the third party control that inherited from Panel instead of contencontrol that needed to be my container. The solution was just to change the ContentControl template to use the third party control.