Thursday, 23 October 2014

ComboBox binding in Workflow activities

Today I was creating a simple activity with a couple of combo boxes, and came across a problem where the binding wasn’t working correctly (well, at all). I had an InArgument<string> property on my activity, and wanted to set this from a combo box on the design surface. I guess I haven’t done this before as it doesn’t work out of the box, and you need to write an IValueConverter to get it working. I’ve trodden this path before but this was a bit of a tricky beast.

After some wailing and gnashing I came up with the following base class converter…

public abstract class ComboBoxToModelItemConverter<T> : IValueConverter
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
T retVal = default(T);

ModelItem mi = value as ModelItem;

if (null != mi)
var arg = mi.GetCurrentValue() as InArgument<T>;

if (null != arg)
var expression = arg.Expression;
var literal = expression as Literal<T>;

if (null != literal)
retVal = literal.Value;

return retVal;

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
return new InArgument<T>((T)value);

I then created a concrete class to bind to InArgument<string>…

public class ComboBoxStringToModelItemConverter : ComboBoxToModelItemConverter<string>

With that created I could then get the binding to work by adding the converter to the binding. I have a class that contains TemplateId and Name, I wish to show the Name on screen but store the TemplateId (and this is mapped to an InArgument<string> on the activity). The XAML is as follows…

<local:ComboBoxStringToModelItemConverter x:Key="comboConverter"/>

<ComboBox ItemsSource="{Binding Templates}" 
SelectedValue="{Binding ModelItem.TemplateId, Converter={StaticResource comboConverter}}"
="TemplateId" DisplayMemberPath="Name" />

With that done it all works as expected. I’m surprised that a converter such as this doesn’t exist in the Workflow libraries – and also in the many, many years I’ve been playing with Workflow that I’ve not needed one. Anyhow, I hope this is of use to someone!


Tech IT Solutions said...

Oh so you finally created the Base Class convertor in order to do the binding task in combo box.You have intelligently found out the way out.

custom writing service reviews said...

Wow looks pretty complex as well as amazing for a amateur like me, great post! Hope to see more of your work soon, you seem like a very talented programmer.

Oliver Maurice said...

Visit this awesome blog for some information on how to write a great research paper. I think that you will find lots of interesting info there

Robert B said...

Nice sharing amazing one keep sharing more thanks for all lovely one avian vet long island

Assignment Help said...

Thank for sharing this information. We provide writing help services at Australi. Hire Now!
Taxation Law Assignment Help

KeiraDoltan said...

Nice blog, The future of the students depends on the grades they obtain in their academic studies. High grades for better job opportunities.
Assignment Provider
All Assignment Help

meldaresearch said...

Our Research Writing Services is normally written by professionals who have sufficient experience in writing academic papers in any discipline. Our customer service is available 24/7, which makes it easy for clients to place orders and receive their Help in Essay Writing on time.

William Shell said...

Hey, Your blog is very informative. It is nice to read such high-quality content. Attractive information on your blog, thank you for taking the time and share with us.Myassignmenthelp delivers high-quality content related to science assignment help writing services.

Unknown said...

I am very happy to visit your blog and read this article. This is the kind of information that needs to be given and not the random misinformation that’s at the other blogs. I appreciate your post. write my paper

Robert B said...

I read your blog post and this is nice blog post.. thanks for taking the time to share with us. have a nice day Network

norhan said...

مكافحة حشرات بالخبر افضل شركة مكافحة حشرات بالخبر
مكافحة حشرات بمكة افضل شركة رش حشرات بمكة
مكافحة حشرات بالمدينة المنورة افضل شركة رش حشرات بالمدينة المنورة
مكافحة حشرات بالدمام افضل شركة مكافحة حشرات بالدمام

ahmed5987 said...

يمكن أن تسبب المزاريب المسدودة أضرارًا في الرطوبة للأفاريز والأسطح وحتى تسبب تسربًا داخليًا. أفضل وقت لتنظيف المزاريب هو بعد سقوط كل الأوراق في الخريف. لسوء الحظ ، إذا كان لديك الكثير من أشجار الصنوبر والأشجار دائمة الخضرة ، فإنها تميل إلى التخلص من الإبر على مدار السنة وقد تضطر إلى تنظيف المزاريب في كثير من الأحيان أو تثبيت حراس المزراب التي تشوه الحطام.
شركة تنظيف بالدمام
شركة تنظيف بالاحساء
شركة كشف تسربات المياه بالاحساء

Pinoy Swertres said...

Enjoy your famous family web blog please bookmarks pinoy Channel to watch abs-cbn and gma shows.

Bunny .cow said...

ปล่อยใจสนุกสุดมันส์ไปกับ Sagaming ผู้ให้บริการบาคาร่าออนไลน์สุดทันสมัยและครบวงจร บริการครบจบในเว็บเดียว มีรูปแบบการเล่นที่หลากหลาย และห้องเดิมพันสุดพิเศษ VIP ให้เลือกเล่นมากกว่า 20 ห้อง เล่นง่าย ได้เงินจริง และจ่ายเงินไวใน 1 นาที และมีโปรโมชั่นต้อนรับสมาชิกใหม่ และโปรโมชั่นเอาใจสมาชิกเก่าอีกมากมาย แจกหนักกจัดเต็มไม่ยั้ง และจัดกิจกรรมดี ๆ ให้ผู้เล่นได้ร่วมสนุกลุ้นรับของรางวัลอื่น ๆ อีกเพียบ อัพเดตกิจกรรมทุกเดือน และมีโปรโมชั่นบาคาร่าสุดคุ้มแจกฟรีตลอดทั้งปี และยังมีระบบฝากถอนที่ปลอดภัยอีกด้วย ฝากง่าย ถอนเงินไว ด้วยแอพพลิเคชั่น True Money Wallet ฟรี ไม่มีค่าบริการ และสามารถทำรายการด้วยตนเองง่าย ๆ ไม่ต้องผ่านแอดมินอีกต่อไป

Angel17 said...

I find this post so informative. Thanks for sharing this one! real estate agent ma

Jacob Wilson said...

This is really interesting, you are a very skilled blogger. | Paypal Login