假设在一个数据模板中,有一个文本框,而在另一个数据模板中,有两个文本框。
根据这个情况,在视图中有一个复选框,并显示每个模板..是否可能实现?
如果我的问题不够清楚,我很抱歉,我已经调查过了,但没有找到答案。
我曾这样做过,我知道这是无用的,但只是为了测试。
<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>