我制作了 2 个数据模板并将其用作资源,我将其应用于列表框,我只能在列表框上应用一个数据模板,这是两个数据模板的代码
<Window.Resources>
<DataTemplate x:Key="template1">
<Canvas Height="40" Width="850">
<Label Height="30" Width="170" Canvas.Top="5" Canvas.Left="80" Background="LightGray"></Label>
<TextBox Height="30" Width="120" Canvas.Top="5" Canvas.Left="300" Background="AliceBlue"></TextBox>
<Label Canvas.Left="420" Canvas.Top="5">$</Label>
</Canvas>
</DataTemplate>
<DataTemplate x:Key="template2">
<Canvas Height="40" Width="850">
<Label Height="30" Width="200" Canvas.Top="5" Canvas.Left="80" Background="LightGray"></Label>
<TextBox Height="30" Width="200" Canvas.Top="5" Canvas.Left="300" Background="AliceBlue"></TextBox>
<Label Canvas.Left="420" Canvas.Top="5">$</Label>
</Canvas>
</DataTemplate>
</Window.Resources>
和列表框的代码
<TabItem>
<Canvas Height="700" Width="850">
<ListBox x:Name="listBox" Height="700" Width="850" ItemTemplate="{StaticResource template1}">
</ListBox>
</Canvas>
</TabItem>
我如何将两个数据模板都应用到列表框,目前只有“模板1”被应用,如何应用“模板2”或者将来有很多数据模板。有什么办法吗??,thanx