WPF——Expander控件(转)

Expander是一个可以展开和折叠的控件,它包含两部分标头和内容。 标头通Header属性来设置,内容通过Conent属性设置,如下面一个简单的例子: Expander ExpandDirection = Down Width = 96 Expander.Header TextBlock Text = 标题 FontWeight = Bold / / Expander.Header Expander.Content TextBlock TextWrapping = Wrap T

  Expander是一个可以展开和折叠的控件,它包含两部分——标头和内容。

  标头通Header属性来设置,内容通过Conent属性设置,如下面一个简单的例子:

  1. <Expander ExpandDirection="Down" Width="96">
  2. <Expander.Header>
  3. <TextBlock Text="标题" FontWeight="Bold"/>
  4. </Expander.Header>
  5. <Expander.Content>
  6. <TextBlock TextWrapping="Wrap"  Text="这里是内容。"/>
  7. </Expander.Content>
  8. </Expander>

  Expander控件的Header和Content都可以为任何对象,只要能正常显示即可。

  下面就是该控件运行时的截图。

  

  这个控件最实用的地方,就是做导航栏。

  1. <StackPanel Margin="20,20" Width="100" Height="460" HorizontalAlignment="Left"
  2. VerticalAlignment="Top">
  3. <Expander VerticalAlignment="Stretch" ExpandDirection="Down" HorizontalContentAlignment="Left" SnapsToDevicePixels="True">
  4. <Expander.Header>
  5. <TextBlock Text="用户管理" FontSize="14" FontWeight="Bold" />
  6. </Expander.Header>
  7. <Expander.Content>
  8. <Grid>
  9. <Grid.RowDefinitions>
  10. <RowDefinition Height="auto"/>
  11. <RowDefinition Height="auto"/>
  12. </Grid.RowDefinitions>
  13. <RadioButton Grid.Row="0">会员管理</RadioButton>
  14. <RadioButton Grid.Row="1">角色管理</RadioButton>
  15. </Grid>
  16. </Expander.Content>
  17. </Expander>
  18. <Expander VerticalAlignment="Stretch" ExpandDirection="Down" HorizontalContentAlignment="Left" SnapsToDevicePixels="True">
  19. <Expander.Header>
  20. <TextBlock Text="文档管理" FontSize="14" FontWeight="Bold" />
  21. </Expander.Header>
  22. <Expander.Content>
  23. <Grid>
  24. <Grid.RowDefinitions>
  25. <RowDefinition Height="auto"/>
  26. <RowDefinition Height="auto"/>
  27. <RowDefinition Height="auto"/>
  28. </Grid.RowDefinitions>
  29. <RadioButton Grid.Row="0">部门资料</RadioButton>
  30. <RadioButton Grid.Row="1">员工资料</RadioButton>
  31. <RadioButton Grid.Row="2">职位资料</RadioButton>
  32. </Grid>
  33. </Expander.Content>
  34. </Expander>
  35. <Expander VerticalAlignment="Stretch" ExpandDirection="Down" HorizontalContentAlignment="Left" SnapsToDevicePixels="True">
  36. <Expander.Header>
  37. <TextBlock Text="采购管理" FontSize="14" FontWeight="Bold" />
  38. </Expander.Header>
  39. <Expander.Content>
  40. <Grid>
  41. <Grid.RowDefinitions>
  42. <RowDefinition Height="auto"/>
  43. <RowDefinition Height="auto"/>
  44. <RowDefinition Height="auto"/>
  45. <RowDefinition Height="auto"/>
  46. <RowDefinition Height="auto"/>
  47. </Grid.RowDefinitions>
  48. <RadioButton Grid.Row="0">采购计划</RadioButton>
  49. <RadioButton Grid.Row="1">需求分析</RadioButton>
  50. <RadioButton Grid.Row="2">采购单</RadioButton>
  51. <RadioButton Grid.Row="3">入库验收</RadioButton>
  52. <RadioButton Grid.Row="4">入库退回</RadioButton>
  53. </Grid>
  54. </Expander.Content>
  55. </Expander>
  56. <Expander VerticalAlignment="Stretch" ExpandDirection="Down" HorizontalContentAlignment="Left" SnapsToDevicePixels="True">
  57. <Expander.Header>
  58. <TextBlock Text="供应商" FontSize="14" FontWeight="Bold" />
  59. </Expander.Header>
  60. <Expander.Content>
  61. <Grid>
  62. <Grid.RowDefinitions>
  63. <RowDefinition Height="auto"/>
  64. <RowDefinition Height="auto"/>
  65. <RowDefinition Height="auto"/>
  66. </Grid.RowDefinitions>
  67. <RadioButton Grid.Row="0">基本资料</RadioButton>
  68. <RadioButton Grid.Row="1">往来单位</RadioButton>
  69. <RadioButton Grid.Row="2">上游供应商</RadioButton>
  70. </Grid>
  71. </Expander.Content>
  72. </Expander>
  73. </StackPanel>

  

  另外,通过ExpandDirection属性可控其展开的方向。

  1. <Expander VerticalAlignment="Stretch" ExpandDirection="Right" HorizontalContentAlignment="Left" SnapsToDevicePixels="True">
  2. ............
  3. </Expander>

WPF——Expander控件(转)

时间: 2024-08-29 23:20:44

WPF——Expander控件(转)的相关文章

在 UWP 中实现 Expander 控件

WPF 中的 Expander 控件在 Windows 10 SDK 中并不提供,本文主要说明,如何在 UWP 中创建这样一个控件.其效果如下图: 首先,分析该控件需要的一些特性,它应该至少包括如下三个属性: Content: 最重要的属性,设置该属性,可以使 Expander 控件显示其内容: Header: 控件的 Header: IsExpand: 当前是否展开. 接下来是定义其 UI,在这里使用 Grid,添加两行,一行显示 Header,一行显示 Content,当 IsExpand

wpf 修改控件Background

以TextBox 控件为例 一  Brushes.颜色 textBoxName.Background = Brushes.Blue; 二 背景色值#FFD2D2D2 1 .textBoxName.Background=new SolidColorBrush((Color)ColorConverter.ConvertFromString("#FFD2D2D2")); 2.textBoxName.Background = new SolidColorBrush(Colors.White);

WPF获取控件内部的ScrollViewer,并控制ScrollViewer操作

//获取内部  ScrollViewer方法 public static T FindVisualChild<T>(DependencyObject obj) where T : DependencyObject        {            if (obj != null)            {                for (int i = 0; i < VisualTreeHelper.GetChildrenCount(obj); i++)          

WPF 布局控件 之 DockPanel

DockPanel为容器控件 主要了解其Dock属性和LastChildFill属性的使用 一.LastChildFill="True" 时 代码: <DockPanel LastChildFill="True"> <Button DockPanel.Dock="Top">Top</Button> <Button DockPanel.Dock="Bottom">Bottom<

WPF条形码控件支持大多数流行的一维和二维条形码Barcode Professional

Barcode Professional for WPF是一款轻量级的 .NET 程序集,为你的WPF程序生成高质量的基于矢量的条码控件,支持大多数流行的一维和二维条形码:Code 39, Code 128, GS1-128, GS1 DataBar (RSS-14),  EAN 13 & UPC, Postal (USPS, British Royal Mail, Australia Post, DHL, etc.), Data Matrix, QR Code, PDF 417, UPS Ma

WPF Popup 控件导致被遮挡内容不刷新的原因

WPF Popup 控件导致被遮挡内容不刷新的原因 周银辉 今天在写一个WPF控件时用到了Popup控件,很郁闷的情况是:当popup关闭时,原来被popup挡住的界面部分不刷新,非要手动刷新一下(比如最大最小化一下窗口),就连网上传说的这个方法也不行 ? 1 2 3 4 5 6 7 8 9 10 public static class UiHelper {     private delegate void NoArgDelegate();     public static void Ref

WPF布局控件常用属性介绍

WPF布局控件常用属性介绍 其它 | 作者:慧都控件网 | 2011-04-06 13:41:57| 阅读 0次 有用(0) 评论(0) 概述:WPF布局控件都是派生自System.Windows.Controls.Panel抽象类的面板,Panel类继承自 FrameworkElement,Panel类本身并没有什么特别的,但是WPF中提供了许多用于布局的控件都继承自Panel类,如 StackPanel控件,WrapPanel,DockPanel,Grid,UniformGrid,Canva

WPF常用控件总结及其应用demo

WPF常用控件总结及其应用 一.控件 1.WrapPanel布局控件:可以实现当空间不足时子控件自动往下一行布局,空间充足时又会自动调整行布局.常用布局控件还有StackPanel(设置其子元素是垂直排列还是水平排列).Grid(通过定义行和列来绘制出一个表格).Canvas(通过指定相对于其的坐标来指定子控件的位置).DockPanel(设置其子元素如何停靠,DockPanel.Left.DockPanel.Right.DockPanel.Top.DockPanel.Bottom). 2.Sc

wpf 保存控件中的内容为图片格式

黄色的是wpf控件的名称! //保存到特定路径            FileStream fs = new FileStream(@"C:\image.png", FileMode.Create);            //对象转换成位图            RenderTargetBitmap bmp = new RenderTargetBitmap((int)this.mediaElement1.ActualWidth, (int)this.mediaElement1.Act