2016-03-03 73 views
1

即時通訊使用Infragistics控件與Theming。模板屬性設置在觸發器上。風格嵌入ControlTemplate使用風格

該模板進一步配置層次結構,所以我不能直接編輯,但我想更改其中一個屬性集。

例如

模板上的觸發器(截)設置

<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> 

我只希望覆蓋邊界(X:NAME = 「ctrlBorder」 )MinHeight屬性。這可能沒有複製我的代碼庫中的整個ControlTemplate。並改變這個單一的財產?

回答

0

據我所知,你不能改變模板,但你可以在你使用該控件的代碼上創建一個自定義行爲(或者添加代碼作爲後面的代碼)。

在該代碼上,檢查控制視覺層次結構並按名稱查找邊框。比你可以改變它的屬性。

重要的是,你會嘗試找上了可視化樹元素(邊境上的情況下)加載事件有對象上雅高,因爲你需要的是視覺上就會被已經

創建

尋找視覺上的層次視覺元素:

 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; 
     } 

這是一個有點髒,但它可以幫助在特定情況下