Hi all,
I have come across another roadblock in my app, and would love to have your assistance.
I have my enum like this:
public enum FuturesTakeProfitMode { ProfitByTarget, ProfitByPriceRange, ProfitByAny }
Using Xamarin Preferences, I have the following in the SettingsViewModel.cs:
public List<string> ProftTakeModes { get { return Enum.GetNames(typeof(FuturesTakeProfitMode)).Select(x => x.SplitCamelCase()).ToList(); } } public override FuturesTakeProfitMode TakeProfitMode { get => (FuturesTakeProfitMode)Preferences.Get(nameof(TakeProfitMode), (int)FuturesTakeProfitMode.ProfitByAny); set => SetPreference(nameof(TakeProfitMode), (int)value); }
In my XAML, I have:
<StackLayout> <Label HorizontalOptions="Start">Profit take mode</Label> <Picker ItemsSource="{Binding ProftTakeModes}" SelectedIndex="{Binding TakeProfitMode, Converter={StaticResource IntEnum}}"></Picker> </StackLayout>
I get the following error when it is run:
System.Reflection.TargetInvocationException: 'Exception has been thrown by the target of an invocation.'
Without binding SelectedIndex, everything works, so I know something is wrong with the binding SelectedIndex.
<StackLayout> <Label HorizontalOptions="Start">Profit take mode</Label> <Picker ItemsSource="{Binding ProftTakeModes}"></Picker> </StackLayout>
I was hoping you could help me figure out what the issue is please.
Thanks,
Michael