Switch cases non-editable set for Switch activity
-
Sunday, December 11, 2011 1:25 PM
Hello
Is it possible to restrict/specify _closed_ set of cases for Switch<string> activity ?
I want to achieve the same behavior as Switch<SomeEnumType> has.
Thanks
All Replies
-
Tuesday, December 13, 2011 5:24 AMModerator
Hi,
Yes, it can be done by using custom types. Below is sample, for your reference:
class Program
{
static void Main(string[] args)
{
WorkflowInvoker.Invoke(CreateWorkflow());
Console.ReadLine();
}public enum CustomEnumType
{
Type1 = 0,
Type2 = 1,
Type3 = 2
}static Activity CreateWorkflow()
{
CustomEnumType cEnum = new CustomEnumType();
cEnum = CustomEnumType.Type1;
Variable<CustomEnumType> var=new Variable<CustomEnumType>{
Default=cEnum
};
Activity activity = new Sequence()
{
Variables = { var },
DisplayName = "SeuenceContainer",
Activities ={
new Switch<CustomEnumType> {
DisplayName="SwitchCustomType",
Expression=var,
Cases={{CustomEnumType.Type1,new WriteLine(){ Text="it is type 1"}},
{CustomEnumType.Type2,new WriteLine(){ Text="it is type 2"}},
{CustomEnumType.Type3,new WriteLine(){ Text="it is type 3"}}}
}
}
};
return activity;
}
}For more information, please refer to:
Usage of the Switch Activity with Custom TypesThanks.
Leo Tang [MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help. -
Tuesday, December 13, 2011 7:43 AM
Thanks for the replay, Leo
The sample you have provided deals with enum type, but the reference link is useful.
I tried to add TypeConverter attribute to 3-rd party class :
TypeDescriptor.AddAttributes(typeof(ThirdPartyClass), new TypeConverterAttribute(typeof(ThirdPartyClassTypeConverter)));
and implemented
GetStandardValuesSupported and GetStandardValuesExclusive methods of ThirdPartyClassTypeConverter.
Unfortunately, these methods are not called when I drag Switch<ThirdPartyClass> to designer surface.
What could be the problem here ?
Thanks
-
Wednesday, December 14, 2011 12:46 PMModerator
Hi,
I assume you want to use standard values in the case statement. Base on my understanding, the typeConverter make the value in the case statement be able to converted implicitly to the same type as expression in the switch statement. However, the typeConverter doesn't apply to Switch activity. Hence, the methods are not called when you drag Switch<ThirdPartyClass> to designer surface. To achieve this, we must add a typeConverter for the built-in Switch activity, which is not supported so far as I know. Thanks.
Leo Tang [MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.- Marked As Answer by LeoTangModerator Sunday, December 18, 2011 2:07 PM
-
Sunday, December 18, 2011 3:19 PM
Thanks, Leo
I've looked at the ViewModel of the CaseBox in reflector- indeed it creates ComboBox from enum values if the type is enum and true,false for Boolean type- no API to customize the logic.

