I want to create a custom Activity. I Need to have a combobox Bind to OData Source
I put a property on my Activity to send the value.
When I select my value from the combobox, the property is not affected
How can i do
lool my designer 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>
Look My vb code
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
Look my 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
Thanks for your reply
I am pretty sure that the issue is with the ModelItem binding on your activity designer. I don't think you can do traditional two way binding on the (WF) ModelItem as its not a 'dynamic' type where by you just access the property by name. Generally the way to access the model item properties is via the properties collection -
Me.ModelItem.Properties("BatchVar").SetValue(text)
Rather than
ModelItem.BatchVar = "text"
I have edited your sample code to include the following event handler for your combobox selected item change event.
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>
Code Behind -
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