帝国网站后台管理系统,dw网页设计代码案例,建筑设计和室内设计哪个好,房屋经纪人网站端口怎么做↑↑↑点击上方蓝字关注我一、概要本文将讲解基于WPF实现一个消息中心的功能#xff0c;比如常见的软件当中会经常收到服务端推送的“新闻”、“公告”等消息。这个时候就需要对这个需求进行分析了。功能分析如下#xff1a;•消息内容显示。•消息管理增、删、批量删除。•消… ↑↑↑点击上方蓝字关注我一、概要本文将讲解基于WPF实现一个消息中心的功能比如常见的软件当中会经常收到服务端推送的“新闻”、“公告”等消息。这个时候就需要对这个需求进行分析了。功能分析如下•消息内容显示。•消息管理增、删、批量删除。•消息分类通知类消息、交互类型消息例如可跳转到某个连接或程序内的模块•消息处理接受、删除、忽略二、实现1.消息内容显示这里考虑自定义的控件为Listbox消息本身是一个多项的内容且需要操作每一项。 ListBoxGrid.Row1MaxHeight335Background{x:Null}BorderThickness0ItemContainerStyle{DynamicResource ListBoxItemStyle}ItemsSource{Binding MessageItem}ScrollViewer.HorizontalScrollBarVisibilityHiddenListBox.ItemsPanelItemsPanelTemplateVirtualizingStackPanel OrientationVertical //ItemsPanelTemplate/ListBox.ItemsPanelListBox.ItemTemplateDataTemplate DataType{x:Type localModel:MessageItemModel}BorderHeight30BorderBrush#FFBDBDBDBorderThickness0,0,0,0.6GridGrid.ColumnDefinitionsColumnDefinition Width1* /ColumnDefinition Width40 //Grid.ColumnDefinitionsDockPanelLabelMaxWidth70Content{Binding PathName}ForegroundRedToolTip{Binding PathName} /LabelMaxWidth130Content{Binding PathContent}ForegroundWhiteToolTip{Binding PathContent} //DockPanelCheckBoxGrid.Column1FlowDirectionRightToLeftIsChecked{Binding PathCheckBoxState} //Grid/Border/DataTemplate/ListBox.ItemTemplate
/ListBox
2.消息管理增、删、批量删除主要容器定下来之后那么接下来每一项消息就是自定义ListboxItem即可针对每一条消息要有具体的处理。例如1.通知类消息只需要确定按钮。2.交互类型消息需要确认、删除、忽略 DataTemplate x:KeySelectedTemplate DataType{x:Type localModel:MessageItemModel}Border BorderBrush#FFBDBDBD BorderThickness0,0,0,0.6StackPanelTextBoxMaxWidth240MaxHeight200Padding0,5,0,0HorizontalAlignmentCenterVerticalAlignmentCenterBackgroundTransparentBorderThickness0FontSize14ForegroundWhiteIsReadOnlyTrueText{Binding PathContent}TextAlignmentCenterTextWrappingWrapWithOverflowToolTip{Binding PathContent}VerticalScrollBarVisibilityAuto /StackPanelMargin5,5,5,9HorizontalAlignmentCenterVerticalAlignmentCenterOrientationHorizontalButtonWidth60Height25Margin5Command{Binding DataContext.ClickAcceptCommand, RelativeSource{RelativeSource AncestorTypeListBox}}CommandParameter{Binding}Content接受Style{StaticResource BlueButtonStyle}Visibility{Binding PathInvitationType, Converter{StaticResource BooleanToVisibilityConverter}} /ButtonWidth60Height25Margin5Command{Binding DataContext.ClickRefuseCommand, RelativeSource{RelativeSource AncestorTypeListBox}}CommandParameter{Binding}Content忽略Style{StaticResource BlueButtonStyle}Visibility{Binding PathInvitationType, Converter{StaticResource BooleanToVisibilityConverter}} /ButtonWidth60Height25Margin5Command{Binding DataContext.ClickAgreeCommand, RelativeSource{RelativeSource AncestorTypeListBox}}CommandParameter{Binding}Content确认Style{StaticResource BlueButtonStyle}Visibility{Binding PathNoticeType, Converter{StaticResource BooleanToVisibilityConverter}} //StackPanel/StackPanel/Border/DataTemplate
3.消息分类这里就是在Model层定义好具体的枚举即可。/// summary
/// 消息处理结果
/// /summary
public enum SysMessageResult
{/// summary/// 未处理/// /summaryUnhandled 0,/// summary/// 同意/// /summaryProcessed 1
}/// summary
/// 消息类型
/// /summary
public enum SysMessageType
{/// summary/// 通知类型/// /summaryNoticeType 0,/// summary/// 其他类型/// /summaryOtherType 1
}
4.消息处理消息处理指的是“确定”、“接受”、“忽略”这三个按钮对消息内容处理的逻辑如果小伙伴需要可根据自己的需要修改。我这里定义如下•确定通常处理通知消息处理仅仅是从消息列表中移除该项不做其他行为。•接受是处理交互类型的按钮处理从消息列表中移除该项且触发其他业务处理行为。•忽略处理所有类型消息只是不显示在UI中但还会存在于消息列表中下次或空闲时间处理消息。