WPF adding control with using code behind RRS feed

  • Question

  • I have wpf control like this as Singleton control

    public class ImageController : GraphicController
            public ImageController()
                : base()
                // some code //

            private static ImageController instanceProperty;
            public static ImageController instance
                get {
                    if (instanceProperty == null)
                        instanceProperty = new ImageController();
                    return instanceProperty; }


    Now I have another Control ToolBox.xaml like below.

    <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" ....>
     <Style x:Key="ToolBoxStyle" TargetType="{x:Type controls:ToolBox}">
    <Setter Property="Template">
                    <ControlTemplate TargetType="{x:Type controls:ToolBox}" x:Name="tests">
    <Grid Margin="0" Grid.Column="0" Grid.Row="0" x:Name="resizableGrid">

    // here i want to add ImageControl from codebehind by usin its instance.


    Here I want to add ImageControl from ToolBox.cs file to inside that Grid. I want to do that because of there
    are copuple of places in my aplication I use same control and needs to share it's property.

    Please let me know how I can do binding here to add control from code behind



    Wednesday, July 10, 2013 2:24 PM


  • Hi,

    You can first get the usercontrol instance and then add in the grid.

    For example, if your grid named "MyGrid" and the instance names"MyUserControl", you can add it like:


    • Marked as answer by Dee Choksi Tuesday, July 16, 2013 8:38 PM
    Monday, July 15, 2013 12:23 PM