您好,登錄后才能下訂單哦!
今天就跟大家聊聊有關如何進行WF4屬性窗格PropertyGrid擴展,可能很多人都不太了解,為了讓大家更加了解,小編給大家總結了以下內容,希望大家根據這篇文章可以有所收獲。
1. 我們有一個CaryActivity活動如下:
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. 上面活動有RepeatCount和FileName屬性,我們會為這兩個屬性在屬性窗格的設置自定義屬性值編輯器,要達到效果如下圖:
3. 分別定義兩個屬性對應的屬性值編輯器如下:
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的構造函數中增加自定義屬性的信息如下,關于AttributeTableBuilder及MetadataStore的使用可參考關于元數據存儲區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());
}
看完上述內容,你們對如何進行WF4屬性窗格PropertyGrid擴展有進一步的了解嗎?如果還想了解更多知識或者相關內容,請關注億速云行業資訊頻道,感謝大家的支持。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。