Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7906557
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T11:02:02+00:00 2026-06-03T11:02:02+00:00

I am using Caliburn Micro in my Project and i have many UserControls and

  • 0

I am using Caliburn Micro in my Project and i have many UserControls and thier viewmodel inherited from PropertyChangedBase, i want this UserControl to be added to a Canvas in my ShellView. I dont want to use IWindowManager from showing Windows instead i want them to get added in a Canvas.

Please help. How can i do that.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T11:02:06+00:00Added an answer on June 3, 2026 at 11:02 am

    If you use ContentControl within your ShellView you can hook into the View-ViewModel binding process of Caliburn.Micro.

    I assume that in your ShellViewModel you have a bunch of properties exposed that are types of ViewModel. If you place a ContentControl in your ShellView (this could be on/as a child of Canvas if that is the container you wish to use to layout your Shell), and then name that control with the name of the property in your ShellViewModel you wish it to be bound to, then Caliburn’s ViewModelBinder will do the rest for you.

    As an example say you have a VM called FizzViewModel and a matching View called FizzView (which is just a UserControl) and you want FizzView to appear on your ShellView you could do something like the following…

    A stripped back ShellViewModel

    public class ShellViewModel : Screen, IShell
    {
        public ShellViewModel(FizzViewModel theFizz)
        {
            TheFizz = theFizz;
        }
    
        public FizzViewModel TheFizz { get; set; }
    }
    

    And its matching ShellView

    <UserControl x:Class="ANamespace.ShellView">
        <Canvas> 
            <ContentControl x:Name="TheFizz"></ContentControl>
        </Canvas> 
    </UserControl>
    

    Here because the ContentControl is named TheFizz, it will be bound by Caliburn to the property with that name on your VM (the one of type FizzViewModel)

    Doing this means you don’t have to laydown your UserControl‘s using their true types on your ShellView, you let Caliburn do the work for you via conventions (which all so means its easy to swap out the type TheFizz if you just add a little more interface indirection).

    UPDATE

    From the extra information you have provided in the comments, I can now see you are actually looking at a problem that requires an ItemsControl.

    The default DataTemplate Caliburn uses looks like the following

    <DataTemplate xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"  
                  xmlns:cal="clr-namespace:Caliburn.Micro;assembly=Caliburn.Micro">  
        <ContentControl cal:View.Model="{Binding}"   
                        VerticalContentAlignment="Stretch"  
                        HorizontalContentAlignment="Stretch" />  
    </DataTemplate>
    

    You will notice that it uses a ContentControl, which has some advantages as I have discussed above. Basically what this will do is allow Caliburn to provide DataTemplateSelector like behaviour to the items in your ItemsControl. So you can add VMs of different types to the collection your ItemsControl is bound to and this default DataTemplate will resolve the type of View to use to display it. The following demos a very simple example of how you can achieve what you want.

    First the ShellViewModel, take note of the BindableCollection named Items

    [Export(typeof(IShell))]
    public class ShellViewModel : IShell 
    {
        public ShellViewModel()
        {
            Items = new BindableCollection<Screen>();
            _rand = new Random();
        }
    
        public BindableCollection<Screen> Items { get; set; }
    
        private Random _rand;
    
        public void AddItem()
        {
            var next = _rand.Next(3);
            var mPosition = System.Windows.Input.Mouse.GetPosition(App.Current.MainWindow);
            switch (next)
            {
                case 0:
                    {
                        Items.Add(new BlueViewModel
                            {
                                X = mPosition.X,
                                Y = mPosition.Y,
                            });
                        break;
                    }
    
                case 1:
                    {
                        Items.Add(new RedViewModel
                        {
                            X = mPosition.X,
                            Y = mPosition.Y,
                        });
                        break;
                    }
                case 2:
                    {
                        Items.Add(new GreenViewModel
                        {
                            X = mPosition.X,
                            Y = mPosition.Y,
                        });
                        break;
                    }
                default:
                    break;
            }
        }
    }
    

    And then a few dummy VM types that you want to display in your Shell. These could be/do anything you like:

    public abstract class SquareViewModel : Screen
    {
        public double X { get; set; }
        public double Y { get; set; }
    }
    
    public class BlueViewModel : SquareViewModel
    {
    
    }
    
    public class RedViewModel : SquareViewModel
    {
    
    }
    
    public class GreenViewModel : SquareViewModel
    {
    
    }
    

    Now a ShellView, note the ItemsControl which binds to the Items property on your ShellViewModel

    <Window x:Class="WpfApplication2.ShellView"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            xmlns:cal="clr-namespace:Caliburn.Micro;assembly=Caliburn.Micro">
    
    <Grid >
            <Grid.RowDefinitions>
                <RowDefinition></RowDefinition>
            </Grid.RowDefinitions>
    
            <ItemsControl x:Name="Items"
                          HorizontalAlignment="Stretch"
                          VerticalAlignment="Stretch">
                <ItemsControl.ItemsPanel>
                    <ItemsPanelTemplate>
                        <Canvas cal:Message.Attach="[Event MouseLeftButtonUp] = [Action AddItem()]"
                                Background="Transparent"></Canvas>
                    </ItemsPanelTemplate>
                </ItemsControl.ItemsPanel>
                <ItemsControl.ItemContainerStyle>
                    <Style TargetType="ContentPresenter">
                        <Setter Property="Canvas.Left" Value="{Binding Path=X}" />
                        <Setter Property="Canvas.Top" Value="{Binding Path=Y}" />
                    </Style>
                </ItemsControl.ItemContainerStyle>
            </ItemsControl>
    </Grid>
    </Window>
    

    And an example of a UserControl that will be used to display the GreenViewModel, create 2 more of these, changing the names to RedView and BlueView and set the backgrounds appropriately to get the demo to work.

    <UserControl x:Class="WpfApplication2.GreenView"
                 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                 Width="30"
                 Height="30">
        <Grid Background="Green"></Grid>
    </UserControl>
    

    What this example does when put together is creates colored squares on the Canvas of your shell based on the location of the mouse click. I think you should be able to take this and extend it to your needs.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using Caliburn.Micro.Telerik conventions project . I have view that dynamically loads telerik
I have this Caliburn.Micro sample project I'm putting together and I am having trouble
I have an .NET 4.0 application using Caliburn.Micro. I want to create a dynamic
Progressbar and Caliburn Micro Hello All, This is my first project using Caliburn so
I'm using Caliburn Micro MVVM. I want to make category selection usercontrol consisting of
I am using Caliburn.Micro I have this WPF View that in design time uses
I am using the convention-based binding from Caliburn.Micro, but I have a small issue:
I am using Caliburn Micro for Implementing MVVM in WPF. I have a static
I have a wpf application using Caliburn.Micro. I need to bind a ListBox to
I have a wpf application using caliburn.micro. It has a datagrid and a combobox.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.