如何重用controltemplates的内容

时间:2016-03-20 16:21:03

标签: c# wpf xaml controltemplate

假设我们有两个带有不同controltemplate触发器但具有相同内容模板的controltemplate:

<ControlTemplate x:Key="A" TargetType="SomeControl">
   <Grid x:Name="reusableGrid"> Grid with a lot of stuff in it,
                                like borders, different shapes and colors. 
                                I'd like to reuse this part in both Templates
   </Grid>
   <ContentPresenter .../>
   <ControlTemplate.Triggers>
      <Trigger Property="AAA" Value="X"> some setter stuff </Trigger>
   </ControlTemplate.Triggers>
</ControlTemplate>

<ControlTemplate x:Key="B" TargetType="SomeControl">
   <reusableGrid/>

   <ContentPresenter .../>
   <ControlTemplate.Triggers>
      <Trigger Property="BBB" Value="Y"> some setter stuff </Trigger>
   </ControlTemplate.Triggers>
</ControlTemplate>

有没有办法在两个模板中使用网格及其内容而不重复? 请注意,我不想让用户控制它。那是因为我需要能够访问我的内容模板触发器中的不同部分(例如,设置边框颜色)。 / p>

0 个答案:

没有答案
相关问题