【发布时间】:2012-02-16 01:33:06
【问题描述】:
想象一下,在一个数据模板中,我有一个文本框,而另一个数据模板中,我有两个文本框。
据此,在视图中有一个复选框,并显示每个模板..这可能吗?
对不起,如果我的问题很可疑,我已经调查过了,但我没有发现。
我是这样做的,我知道这没用,但只是为了测试。
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Window.Resources>
<DataTemplate DataType="{x:Type ContentControl}" x:Key="T1">
<StackPanel>
<TextBox Height="20" />
</StackPanel>
</DataTemplate>
<DataTemplate DataType="{x:Type ContentControl}" x:Key="T2">
<StackPanel>
<TextBox Height="20" />
<TextBox Height="20" />
</StackPanel>
</DataTemplate>
</Window.Resources>
<Grid>
<ContentControl Template="{StaticResource T1}" />
</Grid>
</Window>
【问题讨论】:
-
太棒了。你提到的复选框在哪里?
-
@GarryVass 是的,我没有这样做。我首先以手动方式将模板实现到内容控件..目前的复选框不是问题..
标签: c# wpf templates xaml datatemplate