WorkFlow活动设计器

时间:2015-08-06 08:29:19

标签: wpf vb.net workflow-foundation-4 workflow-activity

我想创建一个自定义Activity。我需要一个组合框绑定到OData源

我在我的Activity上放了一个属性来发送值。

当我从组合框中选择我的值时,该属性不受影响

我该怎么办

告诉我的设计师wpf

<sap:ActivityDesigner
    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"
    xmlns:sapc="clr-namespace:System.Activities.Presentation.Converters;assembly=System.Activities.Presentation"
    xmlns:c="clr-namespace:TFBatchFramwork"  
    xmlns:TFDATAWebReference1="clr-namespace:TFBatchFramwork.TFDATAWebReference1"  
    x:Class="GetBacthVarDesign"    >
    <sap:ActivityDesigner.Resources>
        <ResourceDictionary >
            <sapc:ModelToObjectValueConverter x:Key="ModelToObjectValueConverter"/>
        </ResourceDictionary>
    </sap:ActivityDesigner.Resources>
    <Grid Height="30" HorizontalAlignment="Left" x:Name="grid1" VerticalAlignment="Top" Width="280">
        <Grid.RowDefinitions>
            <RowDefinition Height="30" />
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="100" />
            <ColumnDefinition/>
        </Grid.ColumnDefinitions>
        <Label Content="Variables de lot"  Grid.Row="0" Grid.Column="0" VerticalAlignment="Top" />
        <ComboBox  Grid.Row=" 0" Grid.Column=" 1"  ItemsSource="{Binding}"  
            SelectedValue ="{Binding ModelItem.BatchVar, Converter={StaticResource ModelToObjectValueConverter}, Mode=TwoWay  }" 
            VerticalAlignment="Center"   >

        </ComboBox>


    </Grid>
</sap:ActivityDesigner>

查看我的vb代码

Imports System.Windows.Controls
Imports System.Data.Services.Client

Class GetBacthVarDesign

    Private Context As TFDATAWebReference1.TF5100Context
    Private TrackedVar As DataServiceCollection(Of TFDATAWebReference1.Batch_Var)


    Private Sub GetBacthVarDesign_Loaded(sender As Object, e As Windows.RoutedEventArgs) Handles Me.Loaded
        Context = New TFDATAWebReference1.TF5100Context(New Uri("http://localhost/TFDataWeb/TFDataService.svc"))

        Dim BatchVarQuery = From v In Context.Batch_Var
                       Select v

        TrackedVar = New DataServiceCollection(Of TFDATAWebReference1.Batch_Var)(BatchVarQuery)

        Me.DataContext = TrackedVar

    End Sub
End Class

查看我的活动

Imports System.Activities
Imports System.ComponentModel

<Designer(GetType(GetBacthVarDesign))>
Public NotInheritable Class GetBacthVar
    Inherits CodeActivity

    'Définir un argument d'entrée d'activité de type String
    Public Property BatchVar As TFDATAWebReference1.Batch_Var
    'Public Property BatchvarValues As OutArgument(Of Batch_Var_Values)


    ' Si votre activité retourne une valeur, dérivez de CodeActivity(Of TResult)
    ' et retournez la valeur à partir de la méthode Execute.
    Protected Overrides Sub Execute(ByVal context As CodeActivityContext)
        'Obtenir la valeur runtime de l'argument d'entrée Text
        MsgBox(BatchVar.ToString)
        '   context.SetValue(BatchvarValues, General.CreateVBatchVarValue(BatchVar, New BatchContext))
    End Sub
End Class

感谢您的回复

2 个答案:

答案 0 :(得分:0)

我很确定问题在于你的活动设计师的ModelItem绑定。我不认为你可以对(WF)ModelItem进行传统的双向绑定,因为它不是一个动态的&#39;键入您只需按名称访问该属性的位置。通常,访问模型项属性的方法是通过属性集合 -

Me.ModelItem.Properties("BatchVar").SetValue(text)

而不是

ModelItem.BatchVar = "text"

我已经编辑了您的示例代码,以便为您的组合框选择的项目更改事件包含以下事件处理程序。

Xaml -

<ComboBox  Grid.Row=" 0" Grid.Column=" 1"  ItemsSource="{Binding}"  
        SelectedValue ="{Binding ModelItem.BatchVar, Converter={StaticResource ModelToObjectValueConverter}, Mode=TwoWay  }" 
        VerticalAlignment="Center" SelectionChanged="ComboBox_SelectionChanged"   >
</ComboBox>

背后的代码 -

Private Sub ComboBox_SelectionChanged(sender As Object, e As Windows.Controls.SelectionChangedEventArgs)

    Dim text As String = DirectCast(sender, Windows.Controls.ComboBox).SelectedItem

    Me.ModelItem.Properties("BacthVar").SetValue(text)

End Sub

HTH

答案 1 :(得分:0)

嗨,谢谢你的回复,我试试看,它运作正常。

之前,我找到了一个解决方案,没有使用datacontext来绑定组合框,而是通过代码直接设置ItemsSource

Context = New TFDATAWebReference1.TF5100Context(New Uri(Utility.Uri))

        Dim BatchVarQuery = From v In Context.Batch_Var
                       Select v

        'TrackedVar = New DataServiceCollection(Of TFDATAWebReference1.Batch_Var)(BatchVarQuery)

        'Me.DataContext = TrackedVar

        Cb.ItemsSource = BatchVarQuery

和XAML

<ComboBox  Name="Cb" Grid.Row=" 0" Grid.Column=" 1" DisplayMemberPath="Name"           
        SelectedItem  ="{Binding ModelItem.BatchVar, Converter={StaticResource ModelToObjectValueConverter}, Mode=TwoWay }"
        VerticalAlignment="Center">          
    </ComboBox>

我还有其他问题也许你可以帮助我

您是否已经创建了自定义活动,如流程决定

由于