You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm developing an app right now and I wanted to exploit as much of template 10 as possible, one of the advantages of using template 10 is that I dont have to write many converters, but I'm trying to use whenvalueconverter to map my enum values.
if I switch the Mode=OneWay the program never breaks, but I also need to convert the enum value whenever IsOn is equals to true or false, my enum has two values Sex.Male, Sex.Female if you convert them to Int are equals 0 and 1.
Is there a way to use this converter in a TwoWay mode with enums or should I stick to use a custom converter to acomplish my goal??
Change the property Sex to a DependencyProperty and try.
public Gender Sex
{
get { return (Gender)GetValue(SexProperty); }
set { SetValue(SexProperty, value); }
}
public static readonly DependencyProperty SexProperty =
DependencyProperty.Register(
nameof(Sex), typeof(Gender),
typeof([YourContainerType]),
new PropertyMetadata([initial_default_or_null_here])
);
}
public enum Gender : int
{
Female,
Male
}
I'm developing an app right now and I wanted to exploit as much of template 10 as possible, one of the advantages of using template 10 is that I dont have to write many converters, but I'm trying to use whenvalueconverter to map my enum values.
I think it is not possible but I tried this:
it doesnt show me an error but the program break whenever i use the toggleswitch like this:
if I switch the Mode=OneWay the program never breaks, but I also need to convert the enum value whenever IsOn is equals to true or false, my enum has two values Sex.Male, Sex.Female if you convert them to Int are equals 0 and 1.
Is there a way to use this converter in a TwoWay mode with enums or should I stick to use a custom converter to acomplish my goal??
i would appreciate an answer from the experts and sorry to bring this question here instead of stackoverflow but I found someone else made the question there and there wasnt an answer to it.
reference: https://stackoverflow.com/questions/43561663/valuewhenconverter-and-enum
The text was updated successfully, but these errors were encountered: