6.DatePicker
  
  
   7.Expander
  
  
   
    GroupBox
   
   控件修改
   
    Style
   
   需要注意使用
   
    Grid
   
   分两行进行展示第
   
    0
   
   行显示
   
    Header
   
   第
   
    1
   
   行显示
   
    Content
   
   。
   
    Header
   
   :添加
   
    Border
   
   并边框
   
    BorderThickness="1"
   
   内部新增
   
    ContentPresenter
   
   然后设置
   
    ContentSource="Header"
   
   。
  
  
   引用
   
    Style
   
   后效果如下:
  
  
   
    Content
   
   :添加
   
    Border
   
   并边框
   
    BorderThickness="1 0 1 1"
   
   内部新增
   
    ContentPresenter
   
   。
  
  
   
    引用
   
   
    Style
   
   
    后效果
   
   
    如下:
   
  
  
   
    有更好的方式欢迎推荐。
   
  
  
   1)Styles.GroupBox.xaml 代码如下
  
  
   
    
     <
     
      ResourceDictionary
     
     
      xmlns
     
     =
     
      "http://schemas.microsoft.com/winfx/2006/xaml/presentation"
     
    
   
  
  
   
    xmlns:x
   
   =
   
    "http://schemas.microsoft.com/winfx/2006/xaml"
   
  
  
   
    xmlns:sys
   
   =
   
    "clr-namespace:System;assembly=mscorlib"
   
   >
  
  
   
    <
    
     ResourceDictionary.MergedDictionaries
    
    >
   
  
  
   
    <
    
     ResourceDictionary
    
    
     Source
    
    =
    
     "../Themes/Basic/ControlBasic.xaml"
    
    />
   
  
  
   
    <
    
     ResourceDictionary
    
    
     Source
    
    =
    
     "../Themes/Basic/Animations.xaml"
    
    />
   
  
  
   
    </
    
     ResourceDictionary.MergedDictionaries
    
    >
   
  
  
   
    <
    
     Style
    
    
     TargetType
    
    =
    
     "{x:Type GroupBox}"
    
    
     BasedOn
    
    =
    
     "{StaticResource ControlBasicStyle}"
    
    >
   
   
   
  
  
   
    <
    
     Setter
    
    
     Property
    
    =
    
     "Template"
    
    >
   
  
  
   
    <
    
     Setter.Value
    
    >
   
  
  
   
    <
    
     ControlTemplate
    
    
     TargetType
    
    =
    
     "{x:Type GroupBox}"
    
    >
   
  
  
   
    <
    
     Grid.RowDefinitions
    
    >
   
  
  
   
    <
    
     RowDefinition
    
    
     Height
    
    =
    
     "Auto"
    
    />
   
  
  
   
    <
    
     RowDefinition
    
    
     Height
    
    =
    
     "*"
    
    />
   
  
  
   
    </
    
     Grid.RowDefinitions
    
    >
   
  
  
   
    <
    
     Border
    
    
     Grid.Row
    
    =
    
     "0"
    
    
     BorderThickness
    
    =
    
     "1"
    
    >
   
  
  
   
    <
    
     Border.BorderBrush
    
    >
   
  
  
   
    <
    
     SolidColorBrush
    
    
     Color
    
    =
    
     "{DynamicResource BaseColor}"
    
    />
   
  
  
   
    </
    
     Border.BorderBrush
    
    >
   
  
  
   
    <
    
     Border.Background
    
    >
   
  
  
   
    <
    
     SolidColorBrush
    
    
     Color
    
    =
    
     "{DynamicResource LighterColor}"
    
    />
   
  
  
   
    </
    
     Border.Background
    
    >
   
  
  
   
    <
    
     ContentPresenter
    
    
     Margin
    
    =
    
     "10"
    
   
  
  
   
    ContentSource
   
   =
   
    "Header"
   
  
  
   
    RecognizesAccessKey
   
   =
   
    "True"
   
   />
  
  
   
    </
    
     Border
    
    >
   
  
  
   
    <
    
     Border
    
    
     Grid.Row
    
    =
    
     "1"
    
   
  
  
   
    BorderThickness
   
   =
   
    "1,0,1,1"
   
   
    SnapsToDevicePixels
   
   =
   
    "True"
   
   >
  
  
   
    <
    
     Border.BorderBrush
    
    >
   
  
  
   
    <
    
     SolidColorBrush
    
    
     Color
    
    =
    
     "{StaticResource BaseColor}"
    
    />
   
  
  
   
    </
    
     Border.BorderBrush
    
    >
   
  
  
   
    <
    
     Border.Background
    
    >
   
  
  
   
    <
    
     SolidColorBrush
    
    
     Color
    
    =
    
     "{DynamicResource WhiteColor}"
    
    />
   
  
  
   
    </
    
     Border.Background
    
    >
   
  
  
   
    <
    
     ContentPresenter
    
    
     Margin
    
    =
    
     "4"
    
    />
   
  
  
   
    </
    
     Border
    
    >
   
  
  
   
    </
    
     Grid
    
    >
   
  
  
   
    </
    
     ControlTemplate
    
    >
   
  
  
   
    </
    
     Setter.Value
    
    >
   
  
  
   
    </
    
     Setter
    
    >
   
  
  
   
    </
    
     Style
    
    >
   
  
  
   
    </
    
     ResourceDictionary
    
    >
   
  
  
   2)使用Styles.GroupBox.xaml如下
  
  
   
    
     <
     
      WrapPanel
     
     
      Margin
     
     =
     
      "0,10"
     
     >
    
   
  
  
   
    <
    
     GroupBox
    
    
     Header
    
    =
    
     "GroupBox1"
    
    >
   
  
  
   
    <
    
     Rectangle
    
    
     Fill
    
    =
    
     "{DynamicResource DangerSolidColorBrush}"
    
   
  
  
   
    Width
   
   =
   
    "400"
   
   
    Height
   
   =
   
    "300"
   
   />
  
  
   
    </
    
     GroupBox
    
    >
   
  
  
   
    <
    
     GroupBox
    
    
     Header
    
    =
    
     "GroupBox1"
    
    
     Margin
    
    =
    
     "10,0"
    
    
     IsEnabled
    
    =
    
     "False"
    
    >
   
  
  
   
    <
    
     Rectangle
    
    
     Fill
    
    =
    
     "{DynamicResource LightSolidColorBrush}"
    
   
  
  
   
    Width
   
   =
   
    "400"
   
   
    Height
   
   =
   
    "300"
   
   />
  
  
   
    </
    
     GroupBox
    
    >
   
  
  
   
    </
    
     WrapPanel
    
    >
   
  
  
   [1]
   
    [2]
   
  
  
   GitHub: https://github.com/WPFDevelopersOrg
  
  
   Gitee: https://gitee.com/WPFDevelopersOrg
   
    
     
      返回搜狐,查看更多
     
    
   
  
  
   
   
    责任编辑:
    
    
   
   
    平台声明:该文观点仅代表作者本人,搜狐号系信息发布平台,搜狐仅提供信息存储空间服务。
   
   
    
     阅读 (
     
      )