WPF一个类似于QQ面板的GroupShelf控件Word文档下载推荐.docx

上传人:b****3 文档编号:6205330 上传时间:2023-05-06 格式:DOCX 页数:22 大小:71.71KB
下载 相关 举报
WPF一个类似于QQ面板的GroupShelf控件Word文档下载推荐.docx_第1页
第1页 / 共22页
WPF一个类似于QQ面板的GroupShelf控件Word文档下载推荐.docx_第2页
第2页 / 共22页
WPF一个类似于QQ面板的GroupShelf控件Word文档下载推荐.docx_第3页
第3页 / 共22页
WPF一个类似于QQ面板的GroupShelf控件Word文档下载推荐.docx_第4页
第4页 / 共22页
WPF一个类似于QQ面板的GroupShelf控件Word文档下载推荐.docx_第5页
第5页 / 共22页
WPF一个类似于QQ面板的GroupShelf控件Word文档下载推荐.docx_第6页
第6页 / 共22页
WPF一个类似于QQ面板的GroupShelf控件Word文档下载推荐.docx_第7页
第7页 / 共22页
WPF一个类似于QQ面板的GroupShelf控件Word文档下载推荐.docx_第8页
第8页 / 共22页
WPF一个类似于QQ面板的GroupShelf控件Word文档下载推荐.docx_第9页
第9页 / 共22页
WPF一个类似于QQ面板的GroupShelf控件Word文档下载推荐.docx_第10页
第10页 / 共22页
WPF一个类似于QQ面板的GroupShelf控件Word文档下载推荐.docx_第11页
第11页 / 共22页
WPF一个类似于QQ面板的GroupShelf控件Word文档下载推荐.docx_第12页
第12页 / 共22页
WPF一个类似于QQ面板的GroupShelf控件Word文档下载推荐.docx_第13页
第13页 / 共22页
WPF一个类似于QQ面板的GroupShelf控件Word文档下载推荐.docx_第14页
第14页 / 共22页
WPF一个类似于QQ面板的GroupShelf控件Word文档下载推荐.docx_第15页
第15页 / 共22页
WPF一个类似于QQ面板的GroupShelf控件Word文档下载推荐.docx_第16页
第16页 / 共22页
WPF一个类似于QQ面板的GroupShelf控件Word文档下载推荐.docx_第17页
第17页 / 共22页
WPF一个类似于QQ面板的GroupShelf控件Word文档下载推荐.docx_第18页
第18页 / 共22页
WPF一个类似于QQ面板的GroupShelf控件Word文档下载推荐.docx_第19页
第19页 / 共22页
WPF一个类似于QQ面板的GroupShelf控件Word文档下载推荐.docx_第20页
第20页 / 共22页
亲,该文档总共22页,到这儿已超出免费预览范围,如果喜欢就下载吧!
下载资源
资源描述

WPF一个类似于QQ面板的GroupShelf控件Word文档下载推荐.docx

《WPF一个类似于QQ面板的GroupShelf控件Word文档下载推荐.docx》由会员分享,可在线阅读,更多相关《WPF一个类似于QQ面板的GroupShelf控件Word文档下载推荐.docx(22页珍藏版)》请在冰点文库上搜索。

WPF一个类似于QQ面板的GroupShelf控件Word文档下载推荐.docx

7.

8. 

publicboolIsExpanded

9. 

10. 

get{return(bool)GetValue(IsExpandedProperty);

}

11. 

set{SetValue(IsExpandedProperty,value);

12. 

13.

14. 

//UsingaDependencyPropertyasthebackingstoreforIsSelected. 

Thisenablesanimation,styling,binding,etc

15. 

publicstaticreadonlyDependencyPropertyIsExpandedProperty=DependencyProperty.Register(

16. 

"

IsExpanded"

typeof(bool),typeof(GroupShelfItem),newPropertyMetadata(false,newPropertyChangedCallback(OnIsExpandedChanged)));

17.

18. 

privatestaticvoidOnIsExpandedChanged(DependencyObjectsender,DependencyPropertyChangedEventArgse)

19. 

20. 

GroupShelfItemitem=senderasGroupShelfItem;

21. 

if(item!

=null)

22. 

23. 

item.OnIsExpandedChanged(e);

24. 

25. 

26.

27. 

protectedvirtualvoidOnIsExpandedChanged(DependencyPropertyChangedEventArgse)

28. 

29. 

boolnewValue=(bool)e.NewValue;

30.

31. 

if(newValue)

32. 

33. 

this.OnExpanded();

34. 

35. 

else

36. 

37. 

this.OnCollapsed();

38. 

39. 

}

40.

41. 

#endregion

42.

43. 

#regionSelectionEvents

44.

45. 

46. 

///Raisedwhenselected

47. 

48. 

publiceventRoutedEventHandlerExpanded

49. 

50. 

add{AddHandler(ExpandedEvent,value);

51. 

remove{RemoveHandler(ExpandedEvent,value);

52. 

53.

54. 

publicstaticRoutedEventExpandedEvent=EventManager.RegisterRoutedEvent(

55. 

Expanded"

RoutingStrategy.Bubble,typeof(RoutedEventHandler),typeof(GroupShelfItem));

56.

57. 

58. 

///Raisedwhenunselected

59. 

60. 

publiceventRoutedEventHandlerCollapsed

61. 

62. 

add{AddHandler(CollapsedEvent,value);

63. 

remove{RemoveHandler(CollapsedEvent,value);

64. 

65.

66. 

publicstaticRoutedEventCollapsedEvent=EventManager.RegisterRoutedEvent(

67. 

Collapsed"

68.

69. 

protectedvirtualvoidOnExpanded()

70. 

71. 

GroupShelfparentGroupShelf=this.ParentGroupShelf;

72. 

if(parentGroupShelf!

73. 

74. 

parentGroupShelf.ExpandedItem=this;

75. 

76. 

RaiseEvent(newRoutedEventArgs(ExpandedEvent,this));

77. 

78.

79. 

protectedvirtualvoidOnCollapsed()

80. 

81. 

RaiseEvent(newRoutedEventArgs(CollapsedEvent,this));

 

82. 

83.

84. 

85.

86. 

#regionExpandCommand

87.

88. 

publicstaticRoutedCommandExpandCommand=newRoutedCommand("

Expand"

typeof(GroupShelfItem));

89.

90. 

privatestaticvoidOnExecuteExpand(objectsender,ExecutedRoutedEventArgse)

91. 

92. 

93. 

if(!

item.IsExpanded)

94. 

95. 

item.IsExpanded=true;

96. 

97. 

98.

99. 

privatestaticvoidCanExecuteExpand(objectsender,CanExecuteRoutedEventArgse)

100. 

101. 

e.CanExecute=senderisGroupShelfItem;

102. 

103.

104. 

105.

106. 

publicGroupShelfParentGroupShelf

107. 

108. 

get{returnItemsControl.ItemsControlFromItemContainer(this)asGroupShelf;

109. 

110.

111. 

staticGroupShelfItem()

112. 

113. 

DefaultStyleKeyProperty.OverrideMetadata(typeof(GroupShelfItem),newFrameworkPropertyMetadata(typeof(GroupShelfItem)));

114.

115. 

CommandBindingexpandCommandBinding=newCommandBinding(ExpandCommand,OnExecuteExpand,CanExecuteExpand);

116. 

CommandManager.RegisterClassCommandBinding(typeof(GroupShelfItem),expandCommandBinding);

117. 

118. 

默认的Style

1.<

ResourceDictionary

xmlns="

xmlns:

x="

local="

clr-namespace:

GroupShelfDemo.Controls"

>

<

StyleTargetType="

{x:

Typelocal:

GroupShelfItem}"

SetterProperty="

Template"

7. 

Setter.Value>

ControlTemplateTargetType="

BorderBackground="

{TemplateBindingBackground}"

BorderBrush="

{TemplateBindingBorderBrush}"

BorderThickness="

{TemplateBindingBorderThickness}"

DockPanel>

13. 

ButtonDockPanel.Dock="

Top"

C

ContentTemplateSelector="

{TemplateBindingHeaderTemplateSelector}"

17. 

Command="

{BindingSource={x:

Staticlocal:

GroupShelfItem.ExpandCommand}}"

/>

ContentPresenterx:

Name="

ContentHost"

DockPanel.Dock="

Bottom"

{TemplateBindingContentTemplateSelector}"

C>

ContentPresenter.LayoutTransform>

ScaleTransformx:

ContentHostHeightTransform"

ScaleY="

0.0"

26. 

/ContentPresenter.LayoutTransform>

/ContentPresenter>

/DockPanel>

/Border>

30. 

ControlTemplate.Resources>

Storyboardx:

Key="

OnExpanded"

DoubleAnimationUsingKeyFramesBeginTime="

00:

00"

Storyboard.TargetName="

Storyboard.TargetProperty="

ScaleY"

SplineDoubleKeyFrameKeyTime="

00.08"

Value="

1"

/DoubleAnimationUsingKeyFrames>

/Storyboard>

OnCollapsed"

40. 

42. 

0"

44. 

/ControlTemplate.Resources>

ControlTemplate.Triggers>

TriggerProperty="

True"

Trigger.EnterActions>

BeginStoryboardStoryboard="

{StaticResourceOnExpanded}"

/Trigger.EnterActions>

Trigger.ExitActions>

{StaticResourceOnCollapsed}"

53. 

/Trigger.ExitActions>

/Trigger>

/ControlTemplate.Triggers>

56. 

/ControlTemplate>

/Setter.Value>

/Setter>

/Style>

60.<

/ResourceDictionary>

GroupShelfItem提供了一个Command来操作它的展开和收缩。

同时,在Expand的时候通知GroupShelf处理。

在默认的控件模板中通过按钮来触发这个Command。

GroupShelfPanel

GroupShelf的主要工作就是维护GroupShelfItem展开和收缩时的状态处理。

但是,按照WPF的方式,这个布局的工作不应该由它来完成,而是由我们提供一个ItemsPanel给它。

所以,在GroupShelf之前,GroupShelfPanel应运而生。

写一个Panel最重要的工作就是重载MeasureOverride和ArrangeOverride两个方法。

分析GroupShelfPanel的行为,其实是“指定的孩子填充剩余空间”。

就系统提供的Panel来说,DockPanel跟它的行为是最接近的,因为DockPanel提供了LastChildFill的行为。

既然如此,我们就打开Reflector,从DockPanel里面“借”点代码过来用用:

publicclassGroupShelfPanel:

Panel

///要填充的孩子

publicUIElementChildToFill

get{return(UIElement)GetValue(ChildToFillProperty);

set{SetValue(ChildToFillProperty,value);

11.

publicstaticreadonlyDependencyPropertyChildToFillProperty=DependencyProperty.Register(

ChildToFill"

typeof(UIElement),typeof(GroupShelfPan

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 党团工作 > 入党转正申请

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2