繁体   English   中英

wf 4.0中的活动数据绑定

[英]Activity Databinding in wf 4.0

我想在组合框中显示一些数据类型。 数据类型包装在以下类中:

public class TDataTypeBinder: INotifyPropertyChanged
{
    private string name;
    public string Name
    {
        get
        {
            return name ;
        }
        set
        {
            name = value;
            OnPropertyChanged("Name");
        }
    }

    private DataType datatype;
    public DataType Datatype
    {
        get
        {
            return datatype;
        }
        set
        {
            datatype = value;
            OnPropertyChanged("Datatype");
        }
    }

    /// <summary>
    /// Initializes a new instance of the <see cref="TDataTypeBinder"/> class.
    /// </summary>
    /// <param name="valueToSelect">The value to select.</param>
    public TDataTypeBinder(string valueToSelect)
    {
        Name = valueToSelect;
    }


    public event PropertyChangedEventHandler PropertyChanged;

    private void OnPropertyChanged(string propName)
    {
        PropertyChangedEventHandler eh = this.PropertyChanged;
        if (null != eh)
        {
            eh(this, new PropertyChangedEventArgs(propName));
        }
    }

}

目前我有一个绑定属性:

public CollectionView DatatypesDisplayed
    {
        get
        {

            List<TDataTypeBinder> list = new List<TDataTypeBinder>();
            list.Add(new TDataTypeBinder("String"));
            list.Add(new TDataTypeBinder("Float"));
            list.Add(new TDataTypeBinder("Integer"));

            myDatatypes = new CollectionView(list);
            return myDatatypes;
        }
    }

通过WorkflowElement中的xaml连接:

<... WorkflowViewElement ...
<ComboBox Name="gType" ItemsSource="{Binding Path=ModelItem.DatatypesDisplayed }" DisplayMemberPath="Name" Margin="3" MinWidth="150" Height="20" />

我的组合框gType没有任何内容。 我怎么了 我是WPF和Workflow 4.0的新手,所以我认为这对您来说并不困难。

谢谢你的建议,埃尔

如果UI最初绑定到您的DatatypesDisplayed集合时为null,则随后的更改将不会通知给View ...您是否在类的构造函数中初始化CollectionView

另外-再次检查您是否将View的DataContext设置为类的实例...

干杯,伊恩

编辑:

好的-因此,请在定义您的组合框的xaml中查看以下行:

<ComboBox Name="gType" ItemsSource="{Binding Path=ModelItem.DatatypesDisplayed }" DisplayMemberPath="Name" Margin="3" MinWidth="150" Height="20" />

这意味着应该出现在您的组合框中的“东西”应该位于一个名为DataTypesDisplayed的集合中。 只要该对象公开名为“ Name”的属性,它就可以是任何类型的对象的集合,因为我们将其用于DisplayMemberPath。 此外,此集合应该是称为ModelItem的属性,而ModelItem应该是您视图的DataContext的属性...

放在一起,我希望看到这样的东西:

public partial class MainWindow : Window
{
    public MainWindow()
    {
        InitializeComponent();
        // Set the View's DataContext to be an instance of the class that contains your CollectionView...
        this.DataContext = new MainWindowViewModel();
    }
}


public class MainWindowViewModel
{
    public MainWindowViewModel()
    {
    }

    public object ModelItem { get; set; }
}

public class ModelItem
{
    public CollectionView DataTypesDisplayed { get; set; }
}

我不太确定为什么在ItemsSource绑定的路径中有ModelItem,而您可能会发现不需要它-只需将CollectionView直接放在ViewModel中即可。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM