Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Double click TreeViewItem to show UserControl in MainWindow's Grid

I want to show a UserControl in MainWindow’s Grid, but not working when double click it won’t show the UserControl.

<Grid>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="200" MaxWidth="400" MinWidth="0"/>
        <ColumnDefinition Width="0"/>
        <ColumnDefinition Width="*"/>
    </Grid.ColumnDefinitions>
    <Grid Grid.Column="0" Margin="0,0,0,0">
        <TreeView Background="Transparent">
            <TreeViewItem Header="Purchase" IsExpanded="False">
                <TreeViewItem Header="Material" x:Name="TreeViewItem_Material" MouseDoubleClick="TreeViewItem_Material_MouseDoubleClick"></TreeViewItem>
            </TreeViewItem>
        </TreeView>
    </Grid>
    <GridSplitter Margin="0,0" Width="5"/>
    <Grid Grid.Column="2" x:Name="MainGrid" Margin="0,0,0,0"></Grid>
</Grid>
private void TreeViewItem_Material_MouseDoubleClick(object sender, MouseButtonEventArgs e)
    {
            UserControl material = new Material(); //UserControl: Material.xaml
            MainGrid.Children.Add(material);
    }

Thank you.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Your code works well in my environment as shown below.

The Hello, Material shows when double-click node Material.

Check Material visibility or use a simple UserControl may helps.

enter image description here

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading