Wpf 内容控件,ContentTemplateSelector,如何基于通过绑定提交的值选择staticresource,而不使用datatriggers

Wpf 内容控件,ContentTemplateSelector,如何基于通过绑定提交的值选择staticresource,而不使用datatriggers,wpf,xaml,resourcedictionary,staticresource,Wpf,Xaml,Resourcedictionary,Staticresource,在一个资源字典中,我有几个视图框和一个数据模板,其中包含内容控制。我正在使用样式在视口之间切换,如下所示 <DataTemplate x:Key="foo"> <ContentControl> <ContentControl.Style> <Style TargetType="ContentControl"> <Style.Triggers>

在一个资源字典中,我有几个视图框和一个数据模板,其中包含内容控制。我正在使用样式在视口之间切换,如下所示

<DataTemplate x:Key="foo">
    <ContentControl>
        <ContentControl.Style>
            <Style TargetType="ContentControl">
                <Style.Triggers>
                    <DataTrigger Binding="{Binding Viewbox}" Value="SageCashYes">
                        <Setter Property="Content" Value="{StaticResource SageCashYesViewbox}" />
                    </DataTrigger>
                    <DataTrigger Binding="{Binding Viewbox}" Value="SageCashNo">
                        <Setter Property="Content" Value="{StaticResource SageCashNoViewbox}" />
                    </DataTrigger>
                </Style.Triggers>
            </Style>
        </ContentControl.Style>
    </ContentControl>
</DataTemplate>
有没有办法做这样的事

<DataTemplate x:Key="foo">
      <ContentControl ContentTemplateSelector="{Binding Viewbox}" >
</DataTemplate>
因此,我希望能够告诉它基于此绑定选择适当的Viewbox,但不使用这些数据触发器

我问这个问题是因为视图框里面有向量来绘制图像,这些数据会在短时间内变得巨大。所以,如果有什么事情能让我的生活更轻松,我想知道

编辑

问候
Daniel会帮你吗?据我所知,这将允许我将决策逻辑改为c。所以它需要真正的帮助,因为它仍然是相同的问题,我需要检查绑定的Viewbox值,然后根据该值选择Viewbox。我只是想有一种方法,不用告诉它,就可以使用哪个viewbox,因为它已经有了它的鬃毛?因为我能看到它的声明,而不是没有它的用法,所以很难说你真正能做什么。@XAMlMAX嗨,谢谢你的回答,请原谅我回复得太晚,但我不得不停下来几天,做些别的事情。我在编辑部分添加了您询问的代码。种类Regard如果您希望根据内容自动生成内容,然后,您不应该使用字符串来实现这一点,因为您必须在某个点上定义哪些值是合适的,即在C中。如果您想在其中投入一些精力,您可以将ViewBox属性的类型定义为自定义类,然后将该类用作DataTemplate的定义,如前所述。嗯
     <ListBox ItemTemplate="{StaticResource Foo}
          ItemsSource="{Binding MyList}">
    <ListBox.ItemsPanel>
        <ItemsPanelTemplate>
            <StackPanel Orientation="Horizontal" />
        </ItemsPanelTemplate>
    </ListBox.ItemsPanel>
   </ListBox>

   public class MyViewModel
   {
   public MyViewModel()
       {
          MyList = new List<MyList>()
          {
            new MyItem() {BoolValue = false, Heading = "Bank Payment", Viewbox = "SageCashNo"},
            new MyItem() {BoolValue = true, Heading = "Cash Payment", Viewbox = "SageCashYes"}
          };
       }        

         public List<MyItem> MyList { get; set; }
       }

     public class MyItem
     {
          public bool {BoolValue { get; set; }
          public string Heading { get; set; }
          public string Viewbox { get; set; }
     }