如何注入另一个ControlTemplate?

问题描述

我做了一个CustomControl。

<local:InputControl
      Name1="{lex:Loc ST_Length}"
      TextContent="{Binding Path=Length,Mode=TwoWay,StringFormat=N0,UpdateSourceTrigger=PropertyChanged,ValidatesOnDataErrors=True}"/>
      

及其在Generic.xaml中的认控件模板:

<Style targettype="{x:Type local:InputControl}">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate targettype="{x:Type local:InputControl}">
                <Grid 
                    x:Name="LayoutRoot">       
                    ...

我认为认情况下将使用此模板。
在某些情况下,我想将另一个控件模板应用于CustomControl。我想我可以这样:

<Style x:Key="T2" targettype="{x:Type local:InputControl}">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate targettype="{x:Type local:InputControl}">
                <Grid 
                    x:Name="LayoutRoot">
                    ...
                    

和:

<local:InputControl
      Name1="{lex:Loc ST_Length}"
      Style="{StaticResource=T2}"
      TextContent="{Binding Path=Length,ValidatesOnDataErrors=True}"/>      
                        

但是不起作用。

不用T2,一切都很好,但是现在我得到“找不到资源”。

如果我遗漏了Style / Setter / Setter.Value标签,那也行不通。

对此我该怎么办?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)