Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在项目模板中应用相同的项目模板?_C#_Wpf - Fatal编程技术网

C# 如何在项目模板中应用相同的项目模板?

C# 如何在项目模板中应用相同的项目模板?,c#,wpf,C#,Wpf,我有一个拥有员工列表的员工,所以我需要应用模板,该模板将在一个组合框中连续重复 <ComboBox.ItemTemplate> <DataTemplate > <Grid x:Name="grdItem" Background="Transparent" MouseEnter="grdItem_MouseEn

我有一个拥有员工列表的员工,所以我需要应用模板,该模板将在一个组合框中连续重复

<ComboBox.ItemTemplate>
            <DataTemplate >
                <Grid x:Name="grdItem"  
                         Background="Transparent"
                         MouseEnter="grdItem_MouseEnter"
                         MouseLeave="grdItem_MouseLeave" 
                         VerticalAlignment="Center" Visibility="Visible">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="140" />
                        <ColumnDefinition Width="Auto"/>
                    </Grid.ColumnDefinitions>                        
                                                        <TextBlock Grid.Column="0"                                                 
                                                        VerticalAlignment="Center"
                                                        Margin="1,0,0,10"
                                                        HorizontalAlignment="Left"
                                                        TextTrimming="CharacterEllipsis"
                                                        ToolTip="{Binding Name}"
                                                        Text="{Binding Name}"
                                                       />

                    <Popup x:Name="brdSecondary"                     
                                    Placement="Right"
                                    IsOpen="{Binding IsShowFilters}"
                                    Grid.Column="2"   
                                    PlacementTarget="{Binding ElementName=button}">
                        <Grid  HorizontalAlignment="Right" 
                                         x:Name="grid1111">

                                <ItemsControl Background="White" x:Name="cmbSoftware1" ItemsSource="{Binding Employees}" 
                                                                             KeyboardNavigation.DirectionalNavigation="Contained">
                                    <ItemsControl.ItemTemplate>
                                       --- USE THE SAME TEMPLATE --
                                    </ItemsControl.ItemTemplate>
                                </ItemsControl>
                            </Border>
                        </Grid>
                    </Popup>
                </Grid>                    
            </DataTemplate>
        </ComboBox.ItemTemplate>

---使用相同的模板--

可以用Hierarchial数据模板完成吗?如果没有,我如何才能做到这一点。

根据对象模型中的调平,我可以想出两种解决方案:

  • 一个
    层次结构数据模板
    。不过,您必须弄清楚对象模型是否支持此功能。顺便说一下,据我所知,
    组合框
    不支持
    层次数据模板
    ,因此您必须将
    树视图
    作为选择控件
  • 在更高级别上创建一个
    DataTemplate
    资源,可能在
    Control
    级别上,并重用相同的
    DataTemplate

  • 感谢您的输入,我可以得到一个快速的小样本模板,它应该显示子项目旁边的弹出窗口。