重新托管的设计器中缺少DatePicker值 [英] DatePicker value missing in a re-hosted designer

查看:50
本文介绍了重新托管的设计器中缺少DatePicker值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将DatePicker绑定到活动属性,但无法正常工作.
我正在重新托管WorkflowDesigner并使用代码活动,并且DeadLine属性丢失了.
我将代码简化为一个非常基本的示例.
我的活动如下所示:

  公共密封类ACodeActivity:CodeActivity
{
  DateTime? _DeadLine = DateTime.MinValue;
字符串_Description;

 公共日期时间? DeadLine
  {
   get
br/>  }
   set
    {

  }
  }

  公共字符串描述
  {
    get {返回此._Description; }
   set {this._Description = value; }
  }

       //定义字符串类型的活动输入参数
       public InArgument< string>文字{get;放; }

       //如果您的活动返回值,则从CodeActivity< TResult>
派生//,然后从Execute方法返回值.
      受保护的重写void Execute(CodeActivityContext上下文)
{
                       //获取Text输入参数的运行时值
字符串文本= context.GetValue(this.Text);
       }
    }

我的活动设计师看起来像这样:

< sap:ActivityDesigner x:Class ="WorkflowActivities.Design.ACodeActivityDesigner"
xmlns =" http://schemas.microsoft.com/winfx/2006/xaml/presentation " ;
    xmlns:x =" http://schemas.microsoft.com/winfx/2006/xaml "
    xmlns:sap ="clr-命名空间:System.Activities.Presentation; assembly = System.Activities.Presentation"
                                  xmlns:sapv =" clr-命名空间:System.Activities.Presentation.View; assembly = System.Activities.Presentation"<
    < StackPanel Orientation =垂直">
       < StackPanel Orientation =水平">
<标签内容=描述:"/>
< TextBox Text =" {Binding ModelItem.Description}"宽度="100"/>
</StackPanel>
       < DatePicker SelectedDate =< {Binding ModelItem.DeadLine,Mode = TwoWay}" SelectedDateFormat =短";高度="24". />
    </StackPanel>
</sap:ActivityDesigner>

注册设计师:

   DesignerMetadata metaData =新的DesignerMetadata();
metaData.Register();
    AttributeTableBuilder builder = new AttributeTableBuilder();
   //注册设计师.

   builder.AddCustomAttributes(typeof(ACodeActivity),new Attribute [] {new DesignerAttribute(typeof(ACodeActivityDesigner))});

   //应用元数据.
    MetadataStore.AddAttributeTable(builder.CreateTable());

进入重新托管的设计器,
添加序列
将ACodeActivity添加到序列中
输入Description和DeadLine的值
收起序列
展开序列

结果:Description值保持不变,DeadLine值丢失

我尝试了几种绑定到DisplayDate而不是SelectedDate的组合,并使用OneWay模式没有成功.
我不知道我在这里做错什么了吗,或者DatePicker,ModelItem或别的地方.似乎缺少通知(例如修改selectedDate不会更新DisplayDate).
属性网格始终显示正确的值.调试时,ModelItem.GetCurrentValue()和ModelItem.Properties ["DeadLine"].Value都是正确的.
请帮忙.

 

解决方案

Jariza,您好,

我对DatePicker控件不是很熟悉,所以我已将您的问题转发给WPF团队.同时,通过在DatePicker的Loaded事件中添加事件处理程序并显式设置Picker的值,我能够使您的示例工作.

此代码目前应该对您解除阻止:

<字体= Consolas大小= 2> <字体= Consolas大小= 2>

      私有无效DatePicker_Loaded(对象发送者,RoutedEventArgs e)
       {
                       ((DatePicker)sender).SelectedDate =(DateTime)ModelItem.Properties ["DeadLine"].Value.GetCurrentValue();
}

希望有帮助,
-Eric

 

 


I'm trying to bind a DatePicker to an activity property but it's not working correctly.
I'm rehosting the WorkflowDesigner and using a code activity, and the DeadLine property is being lost.
I simplified the code to a very basic example.
My activity looks like this:

    public sealed class ACodeActivity : CodeActivity
    {
  DateTime? _DeadLine = DateTime.MinValue;
  string _Description;

  public DateTime? DeadLine
  {
   get
   {
    return this._DeadLine;
   }
   set
   {
    this._DeadLine = value;
   }
  }

  public string Description
  {
   get { return this._Description; }
   set { this._Description = value; }
  }

        // Define an activity input argument of type string
        public InArgument<string> Text { get; set; }

        // If your activity returns a value, derive from CodeActivity<TResult>
        // and return the value from the Execute method.
        protected override void Execute(CodeActivityContext context)
        {
            // Obtain the runtime value of the Text input argument
            string text = context.GetValue(this.Text);
        }
    }

my activity designer looks like this:

<sap:ActivityDesigner x:Class="WorkflowActivities.Design.ACodeActivityDesigner"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:sap="clr-namespace:System.Activities.Presentation;assembly=System.Activities.Presentation"
    xmlns:sapv="clr-namespace:System.Activities.Presentation.View;assembly=System.Activities.Presentation">
    <StackPanel Orientation="Vertical">
        <StackPanel Orientation="Horizontal">
            <Label Content="Description:"/>
            <TextBox Text="{Binding ModelItem.Description}" Width="100"/>
        </StackPanel>
        <DatePicker SelectedDate="{Binding ModelItem.DeadLine, Mode=TwoWay}" SelectedDateFormat="Short" Height="24" />
    </StackPanel>
</sap:ActivityDesigner>

registering the designer:

    DesignerMetadata metaData = new DesignerMetadata();
    metaData.Register();
    AttributeTableBuilder builder = new AttributeTableBuilder();
    // Register Designers.

    builder.AddCustomAttributes(typeof(ACodeActivity), new Attribute[] { new DesignerAttribute(typeof(ACodeActivityDesigner)) });

    // Apply the metadata.
    MetadataStore.AddAttributeTable(builder.CreateTable());

Go into the rehosted Designer,
add a Sequence
add a ACodeActivity into the Sequence
enter values for Description and DeadLine
collapse the Sequence
expand the Sequence

Result: The Description value is kept, the DeadLine value is lost

I tried several combinations binding to DisplayDate instead of to SelectedDate and using OneWay Mode with no success.
I don't know if I'm doing something wrong here or it is a problem in DatePicker, ModelItem, or somewhere else. It seems like a notification is missing (something like modifying the selectedDate doesn't update the DisplayDate).
The property grid shows the correct value all the time. When debugging, both ModelItem.GetCurrentValue() and ModelItem.Properties["DeadLine"].Value are correct.
Please help.

 

解决方案

Hi Jariza,

I'm not very familiar with the DatePicker control myself, so I've forwarded you question to the WPF team.  In the meantime, I was able to get your sample to work by adding an event handler to the Loaded event of the DatePicker and set the value of the Picker explicitly.

This code should unblock you for the moment:

        private void DatePicker_Loaded(object sender, RoutedEventArgs e)
        {
            ((DatePicker)sender).SelectedDate = (DateTime)ModelItem.Properties["DeadLine"].Value.GetCurrentValue();
        }

Hope this helps,
-Eric

 

 


这篇关于重新托管的设计器中缺少DatePicker值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆