简体   繁体   English

同一网格中有2个相同的控件? (WPF / xaml)

[英]2 identical Controls in the same Grid ? (WPF/xaml)

Here is a simple code that exposes my problem : 这是暴露我的问题的简单代码:

<Grid>
    <TreeView Name="myTreeViewEvent" >
        <TreeViewItem Header="Employee1"/>
    </TreeView>
    <TreeView Name="myTreeViewEvent2" >
        <TreeViewItem Header="Employee2"/>
    </TreeView>
</Grid>

The thing is that my 2nd Treeview "overwrites" the 1st one... Is there a way to change the behaviour so that the 2nd Treeview is "added" to the 1st one ? 问题是我的第二个树视图“覆盖”了第一个树视图...是否可以更改行为,以便将第二个树视图“添加”到第一个树视图?

(nb : no, I can't put them in the same Treeview cause in my "real" code, I got 2 different Treeviews that I CAN'T merge... and I gotta display them in the same grid !) (nb:不,我不能在“真实”代码中将它们放在相同的Treeview中,我无法合并两个不同的Treeview ...我必须将它们显示在同一网格中!)

Try this 尝试这个

<Grid>
    <Grid.RowDefinitions>
        <RowDefinition />
        <RowDefinition />
    </Grid.RowDefinitions>
    <TreeView Name="myTreeViewEvent" >
        <TreeViewItem Header="Employee1"/>
    </TreeView>
    <TreeView Grid.Row="1" Name="myTreeViewEvent2" >
        <TreeViewItem Header="Employee2"/>
    </TreeView>
</Grid>

EDIT Then what prevents you from using this approach? 编辑然后是什么阻止您使用此方法?

<Grid>
        <StackPanel>    
            <TreeView Name="myTreeViewEvent">
                <TreeViewItem Header="Employee1"/>
            </TreeView>
            <TreeView Name="myTreeViewEvent2">
                <TreeViewItem Header="Employee2"/>
            </TreeView>
        </StackPanel>
</Grid>

In this case there is no strict division. 在这种情况下,没有严格的划分。 The items will strech up. 这些项目将努力。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM