工作流 Activity 设计师

WorkFlow Activity Designer

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

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

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

我该怎么办

看看我的设计师 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

看看我的activity

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

感谢您的回复

我很确定问题出在您的 activity 设计器上的 ModelItem 绑定。我认为您不能对 (WF) ModelItem 进行传统的双向绑定,因为它不是 'dynamic' 类型,您只需按名称访问 属性 即可。通常访问模型项属性的方法是通过属性集合 -

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

您好,感谢您的回复,我试了一下,效果很好。

之前,我找到了一个解决方案,不使用数据上下文来绑定组合框,而是通过这样的代码直接设置 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>

我还有一个问题也许你可以帮我

你是否已经创建了一个自定义的activity像一个flowdecision

谢谢