相关疑难解决方法(0)

WPF:如何设置内容控件的数据模板触发器?

我想创建一个包含一个组合框和一个内容控件的用户控件.在组合框中进行的选择应确定内容控件将使用的数据模板.我读过这篇文章,它几乎展示了我想要实现的目标.

组合框中填充了enum ModelType值,可以是PersonCompany.如果用户选择Person,内容控件应使用personTemplate数据模板; 并companyTemplateCompany.

我对内容控件的XAML代码感到困惑.这是我创建的但我不能使它工作:

<UserControl.Resources>
  ...
  <DataTemplate x:Key="personTemplate" ...>
  <DataTemplate x:Key="companyTemplate" ...>
  ...
</UserControl.Resources>
...
<ContentControl x:Name="Account">
  <ContentControl.ContentTemplate>
    <DataTemplate>
      <DataTemplate.Triggers>
        <DataTrigger Binding="{Binding AccountType}" Value="Person">
        <!-- I doubt the Value property is set correctly. -->
        <!-- It should be a value of an enum ModelType -->
          <Setter 
              TargetName="Account" 
              Property="ContentTemplate" 
              Value="{StaticResource personTemplate}" />
          <!-- The setter is unaware of the target name, i.e. content control …
Run Code Online (Sandbox Code Playgroud)

wpf xaml

35
推荐指数
1
解决办法
4万
查看次数

标签 统计

wpf ×1

xaml ×1