我想创建一个自定义活动。我需要一个组合框绑定到OData源代码
我在我的活动中放置了一个属性来发送值。
当我从组合框中选择我的值时,属性不受影响。
我该怎么办?
洗脸我的设计师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谢谢你的答复
发布于 2015-08-07 14:12:11
我很确定问题在于活动设计器上的ModelItem绑定。我不认为您可以在(WF) ModelItem上执行传统的双向绑定,因为它不是一个“动态”类型,您只需按名称访问属性。通常,访问模型项属性的方法是通过属性集合-
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 SubHTH
发布于 2015-08-07 15:09:05
嗨,谢谢你的回复,我试过了,效果很好。
在此之前,我找到了一个解决方案:不使用数据文本绑定combobox,而是通过如下代码直接设置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>我还有另外一个问题也许你可以帮我
您是否已经创建了一个自定义活动,如Like决策?
谢谢
https://stackoverflow.com/questions/31850621
复制相似问题