新聞中心
本文將講解的是WF4屬性窗格PropertyGrid擴(kuò)展,希望對(duì)大家了解Windows Workflow Foundation框架有所幫助。

十余年的泰山網(wǎng)站建設(shè)經(jīng)驗(yàn),針對(duì)設(shè)計(jì)、前端、開發(fā)、售后、文案、推廣等六對(duì)一服務(wù),響應(yīng)快,48小時(shí)及時(shí)工作處理。全網(wǎng)營(yíng)銷推廣的優(yōu)勢(shì)是能夠根據(jù)用戶設(shè)備顯示端的尺寸不同,自動(dòng)調(diào)整泰山建站的顯示方式,使網(wǎng)站能夠適用不同顯示終端,在瀏覽器中調(diào)整網(wǎng)站的寬度,無論在任何一種瀏覽器上瀏覽網(wǎng)站,都能展現(xiàn)優(yōu)雅布局與設(shè)計(jì),從而大程度地提升瀏覽體驗(yàn)。成都創(chuàng)新互聯(lián)公司從事“泰山網(wǎng)站設(shè)計(jì)”,“泰山網(wǎng)站推廣”以來,每個(gè)客戶項(xiàng)目都認(rèn)真落實(shí)執(zhí)行。
#T#
1. 我們有一個(gè)CaryActivity活動(dòng)如下:
- namespace CaryPropertyGridExten
- {
- public sealed class CaryActivity : CodeActivity
- {
- public InArgument Text { get; set; }
- public double RepeatCount { get; set; }
- public string FileName { get; set; }
- protected override void Execute(CodeActivityContext context)
- {
- }
- }
- }
2. 上面活動(dòng)有RepeatCount和FileName屬性,我們會(huì)為這兩個(gè)屬性在屬性窗格的設(shè)置自定義屬性值編輯器,要達(dá)到效果如下圖:
3. 分別定義兩個(gè)屬性對(duì)應(yīng)的屬性值編輯器如下:
- namespace CaryPropertyGridExten
- {
- class CustomInlineEditor : PropertyValueEditor
- {
- public CustomInlineEditor()
- {
- this.InlineEditorTemplate = new DataTemplate();
- FrameworkElementFactory stack = new FrameworkElementFactory(typeof(StackPanel));
- FrameworkElementFactory slider = new FrameworkElementFactory(typeof(Slider));
- Binding sliderBinding = new Binding("Value");
- sliderBinding.Mode = BindingMode.TwoWay;
- slider.SetValue(Slider.MinimumProperty, 0.0);
- slider.SetValue(Slider.MaximumProperty, 100.0);
- slider.SetValue(Slider.ValueProperty, sliderBinding);
- stack.AppendChild(slider);
- FrameworkElementFactory textb = new FrameworkElementFactory(typeof(TextBox));
- Binding textBinding = new Binding("Value");
- textb.SetValue(TextBox.TextProperty, textBinding);
- textb.SetValue(TextBox.IsEnabledProperty, false);
- stack.AppendChild(textb);
- this.InlineEditorTemplate.VisualTree = stack;
- }
- }
- }
- namespace CaryPropertyGridExten
- {
- class FilePickerEditor : DialogPropertyValueEditor
- {
- public FilePickerEditor()
- {
- this.InlineEditorTemplate = new DataTemplate();
- FrameworkElementFactory stack = new FrameworkElementFactory(typeof(StackPanel));
- stack.SetValue(StackPanel.OrientationProperty, Orientation.Horizontal);
- FrameworkElementFactory label = new FrameworkElementFactory(typeof(Label));
- Binding labelBinding = new Binding("Value");
- label.SetValue(Label.ContentProperty, labelBinding);
- label.SetValue(Label.MaxWidthProperty, 90.0);
- stack.AppendChild(label);
- FrameworkElementFactory editModeSwitch = new FrameworkElementFactory(typeof(EditModeSwitchButton));
- editModeSwitch.SetValue(EditModeSwitchButton.TargetEditModeProperty, PropertyContainerEditMode.Dialog);
- stack.AppendChild(editModeSwitch);
- this.InlineEditorTemplate.VisualTree = stack;
- }
- public override void ShowDialog(PropertyValue propertyValue, IInputElement commandSource)
- {
- Microsoft.Win32.OpenFileDialog ofd = new Microsoft.Win32.OpenFileDialog();
- if (ofd.ShowDialog() == true)
- {
- propertyValue.Value = ofd.FileName.Substring(ofd.FileName.LastIndexOf('\\') + 1);
- }
- }
- }
- }
4. 在CaryActivity的構(gòu)造函數(shù)中增加自定義屬性的信息如下,關(guān)于AttributeTableBuilder及MetadataStore的使用可參考關(guān)于元數(shù)據(jù)存儲(chǔ)區(qū)MetadateStore及AttributeTableBuilder這篇文章。
- public CaryActivity()
- {
- AttributeTableBuilder builder = new AttributeTableBuilder();
- builder.AddCustomAttributes(typeof(CaryActivity), "RepeatCount", new EditorAttribute(typeof(CustomInlineEditor), typeof(PropertyValueEditor)));
- builder.AddCustomAttributes(typeof(CaryActivity), "FileName", new EditorAttribute(typeof(FilePickerEditor), typeof(DialogPropertyValueEditor)));
- MetadataStore.AddAttributeTable(builder.CreateTable());
- }
本文標(biāo)題:淺析WF4屬性窗格PropertyGrid擴(kuò)展
轉(zhuǎn)載注明:http://m.5511xx.com/article/ccsjojh.html


咨詢
建站咨詢
