IValueConverter InArgument<string> to string
-
Thursday, December 02, 2010 8:16 AM
I understand if you want to have a TextBox control or other WPF controls in an Activity Designer, to bind it to an actual property you will need a IValueConverter.
Is there any of such converter available natively, like ArgumentToExpressionConverter? If not, how do you convert a value to InArgument and vice versa? For example if I have a TextBox and a string InArgument, I will need a ArgumentToStringConverter, don't I?
All Replies
-
Thursday, December 02, 2010 6:49 PM
for the converter from argument to wpf control, I think you need to write your own converter inherited from IValueConverter
this is the sample
http://msdn.microsoft.com/en-us/library/system.windows.data.ivalueconverter.aspx
- Proposed As Answer by Jeff Cao Thursday, December 02, 2010 8:00 PM
- Unproposed As Answer by Louis Rhys Friday, December 03, 2010 2:49 AM
-
Friday, December 03, 2010 2:49 AMyes I am aware of that. My question was, how to convert Inargument<string> to string, and vice versa
-
Friday, December 03, 2010 3:42 AMwhat do you mean by vice versa?
-
Friday, December 03, 2010 6:59 AMsorry, i mean from Inargument<string> to string AND from string to InArgument<String>. Because i will need both Convert and ConvertBack methods, right?
-
Friday, December 03, 2010 9:04 AM
can you have a try on this converter, it works on my machine with a custom activity having WPF textbox
public class ArgumentToStringConverter : IValueConverter
{
object IValueConverter.Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
object convertedValue = null;
if (value != null)
{
ModelItem argumentModelItem = value as ModelItem;
if (argumentModelItem != null &&
argumentModelItem.Properties["Expression"] != null &&
argumentModelItem.Properties["Expression"].Value != null)
{
if (argumentModelItem.Properties["Expression"].ComputedValue.GetType() == typeof(Literal<string>))
{
convertedValue = (argumentModelItem.Properties["Expression"].ComputedValue as Literal<String>).Value;
}
else
{
convertedValue = (argumentModelItem.Properties["Expression"].ComputedValue as VisualBasicValue<string>).ExpressionText;
}
}
}
return convertedValue;
}object IValueConverter.ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{// Convert string value to InArgument<string>
string itemContent = (string)value;
VisualBasicValue<string> vbArgument = new VisualBasicValue<string>(itemContent);
InArgument<string> inArgument = new InArgument<string>(vbArgument);
return inArgument;
}
}- Marked As Answer by Andrew_ZhuModerator Friday, December 10, 2010 5:57 AM
-
Monday, December 06, 2010 9:24 AMModerator
Hi, Louis
Here is another sample,I created it one year ago, could be helpful to you:
http://xhinker.com/2009/11/29/DotNetWF4UseTypeConverter.aspx
Regards
This posting is provided "AS IS" with no warranties, and confers no rights. Microsoft Online Community Support. My Blog:http://xhinker.com "Microsoft Windows Workflow Foundation 4.0 Cookbook"

