【问题标题】:Style embedded ControlTemplate using Style使用 Style 嵌入 ControlTemplate 样式
【发布时间】:2016-03-03 17:48:48
【问题描述】:

我将 Infragistics 控件与 Theming 一起使用。模板属性设置在触发器上。

该模板配置在层次结构的更上层,因此我无法直接编辑,但我想更改其中一个属性集。

例如

在触发器上设置的模板(截断)

<Style x:Key="FxtPaneTabItemStyle" TargetType="{x:Type igDock:PaneTabItem}">
  <Setter Property="TextBlock.TextTrimming" Value="CharacterEllipsis" />
    <Style.Triggers>
      <Trigger Property="igDock:XamDockManager.PaneLocation" Value="Unpinned">
        <Setter Property="Template" Value="{DynamicResource {x:Static igDock:PaneTabItem.DockableTabItemTemplateKey}}" />
      </Trigger>
  </Style.Triggers>
</Style>

在无法访问的代码中配置的模板(截断)

<ControlTemplate x:Key="{x:Static igDock:PaneTabItem.DockableTabItemTemplateKey}" TargetType="{x:Type igDock:PaneTabItem}">
 <Border x:Name="ctrlBorder" SnapsToDevicePixels="true" MinHeight="25">
  <controls:CardPanel>
  <controls:CardPanel x:Name="Background">
   <Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Width="Auto" Height="25">
    <Border x:Name="Border" Margin="0,0,0,0" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" SnapsToDevicePixels="True"/>
    <Border x:Name="HighlightBorder" Margin="0" BorderBrush="{DynamicResource {x:Static igDock:DockManagerBrushKeys.TabbedListNotActiveInnerBorderFillKey}}" BorderThickness="0" SnapsToDevicePixels="True"/>
   </Grid>
  </controls:CardPanel>
 </Border>
<ControlTemplate.Triggers>
</ControlTemplate.Triggers>

我只想覆盖 Border (x:Name="ctrlBorder") MinHeight 属性。如果不复制我的代码库中的整个 ControlTemplate,这是否可能。并更改此单一属性?

【问题讨论】:

    标签: wpf wpf-controls infragistics wpf-style


    【解决方案1】:

    据我所知,您无法更改模板,但您可以在使用该控件的代码上创建自定义行为(或添加代码作为后面的代码)。

    在该代码上,查看控件视觉层次结构并按名称查找边框。比你可以改变它的属性。

    Loaded 事件与该对象一致之后 尝试在可视化树上找到元素(边框上的边框)很重要,因为您需要视觉效果已经被创建

    在视觉层次中寻找视觉元素:

            public static List<T> FindVisualChildren<T>(DependencyObject depObj, bool searchWithinAFoundT = true) where T : DependencyObject
            {
                List<T> list = new List<T>();
                if (depObj != null)
                {
                    for (int i = 0; i < VisualTreeHelper.GetChildrenCount(depObj); i++)
                    {
                        DependencyObject child = VisualTreeHelper.GetChild(depObj, i);
                        if (child != null && child is T)
                        {
                            list.Add((T)child);
    
                            // this means that an element is not expected to contain elements of his type
                            if (!searchWithinAFoundT) { continue; }
                        }
    
                        List<T> childItems = FindVisualChildren<T>(child, searchWithinAFoundT);
                        if (childItems != null && childItems.Count > 0)
                        {
                            foreach (var item in childItems)
                            {
                                list.Add(item);
                            }
                        }
                    }
                }
                return list;
            }
    

    它有点脏,但它可以在特定情况下有所帮助

    【讨论】:

      猜你喜欢
      • 2011-09-02
      • 1970-01-01
      • 2010-12-11
      • 2015-02-28
      • 1970-01-01
      • 2011-01-25
      • 1970-01-01
      • 2013-04-04
      • 1970-01-01
      相关资源
      最近更新 更多