拨号地址怎么做网站,数字创意设计包括哪些工具,网站开发培训班 上地,wordpress 模板分页好久没有更新文章,今天抽空来分享一下最近玩耍的自定义控件;里面包含了自定义控件、依赖属性和路由事件;来看看最终实现的效果:1、先来看看前台Xaml布局和绑定:Style TargetType{x:Type Cores:UploadWithProgressControl}Setter PropertyTemplat…好久没有更新文章,今天抽空来分享一下最近玩耍的自定义控件;里面包含了自定义控件、依赖属性和路由事件;来看看最终实现的效果:1、先来看看前台Xaml布局和绑定:Style TargetType{x:Type Cores:UploadWithProgressControl}Setter PropertyTemplateSetter.ValueControlTemplate TargetType{x:Type Cores:UploadWithProgressControl}WrapPanelGridTextBox Background#323232Style{StaticResource TriggerTextBox}IsReadOnlyTrue Text{TemplateBinding FilePath,Converter{StaticResource FilePathToFileNameConverter}}VerticalContentAlignmentCenter/Button x:NameSelectFileButton Style{StaticResource OpenFileButton}HorizontalAlignmentRight VerticalAlignmentCenter Margin0,15,5,15//GridButton Content更新 x:NameUpdateButton Margin10,10,0,10Style{StaticResource BaseButton}IsEnabled{TemplateBinding CurrentState,Converter{StaticResource UpdateStateEnumToButtonIsEnabledConverter}}//WrapPanel/ControlTemplate/Setter.Value/Setter
/Style2、后台代码,关键点在TemplatePart和GetTemplateChild:3、对于文件的选择无非就是控件内部依赖属性的处理private void SelectFileButton_Click(object sender, RoutedEventArgs e){System.Windows.Forms.OpenFileDialog openFileDialog new System.Windows.Forms.OpenFileDialog{Title 选择要升级的文件,Filter 升级程序(*.bin)|*.bin|所有文件(*.*)|*.*};System.Windows.Forms.DialogResult isSelected openFileDialog.ShowDialog();if(isSelected System.Windows.Forms.DialogResult.OK){//选择的文件string fileName openFileDialog.FileName;FilePath fileName;CurrentState UpdateStateEnum.SelectFile;OperateType OperateTypeEnum.SelectFile;}}4、对于更新按钮就需要自定义路由事件了,毕竟是处理控件以外的逻辑了:5、可以用Code Snippet快速创建路由事件https://andrewharcourt.com/articles/code-snippet-for-wpf-routed-event6、最后来个调用完事:Cores:UploadWithProgressControl VerticalAlignmentCenter HorizontalAlignmentCenterIsUploading{Binding FirstData.IsUpload,ModeTwoWay}ProgressValue{Binding FirstData.ProgressValue,ModeTwoWay}CurrentState{Binding FirstData.UpdateState,ModeTwoWay}UpdateUploadWithProgressControl_Click/最终简单的效果先这样吧;以后有时间的话,可以再去摸索一下更复杂的效果;编程不息、Bug不止、无Bug、无生活;改bug的冷静、编码的激情、完成后的喜悦、挖坑的激动 、填坑的兴奋;这也许就是屌丝程序员的乐趣吧;今天就到这里吧;希望自己有动力一步一步坚持下去;生命不息,代码不止;大家抽空可以看看今天分享的效果,有好的意见和想法,可以在留言板随意留言;我看到后会第一时间回复大家,多谢大家的一直默默的关注和支持!如果觉得不错,那就伸出您的小手点个赞并关注一下