public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            UserSexType result = UserSexType.Unknown;

            if (value is string stringValue)
            {
                result = UserSexType.Unknown.ParseLocalizedName <UserSexType>(stringValue);
            }

            return(result);
        }
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            UserSexType result = UserSexType.Unknown;

            if (value is int intValue)
            {
                result = (UserSexType)((byte)intValue);
            }
            else if (value is UserSexType typeValue)
            {
                result = typeValue;
            }

            return(result.GetLocalizedName());
        }
Example #3
0
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            UserSexType result = UserSexType.Unknown;

            if (value is int intValue)
            {
                result = (UserSexType)((byte)intValue);
            }
            else if (value is UserSexType typeValue)
            {
                result = typeValue;
            }

            return(result != UserSexType.Unknown
                ? Visibility.Visible
                : Visibility.Collapsed);
        }
Example #4
0
        private async void EditComboBoxSex_Click(object sender, RoutedEventArgs e)
        {
            UserProfileStat element = sender as UserProfileStat;

            BindingExpression binding = element?.GetBindingExpression(UserProfileStat.StatValueProperty);

            if (binding == null)
            {
                return;
            }

            ProfileSchema sourceClass    = (ProfileSchema)binding.ResolvedSource;
            PropertyInfo  sourceProperty = typeof(ProfileSchema).GetProperty(binding.ResolvedSourcePropertyName);

            if (sourceClass == null || sourceProperty == null)
            {
                return;
            }

            string title     = LocalizationUtils.GetLocalized("ProfileEditingTitle");
            string enterName = LocalizationUtils.GetLocalized("EnterTitle");

            ReadOnlyCollection <string> localizedNames =
                new ReadOnlyCollection <string>(UserSexType.Unknown.GetLocalizedNames());

            UserSexType oldValue = (UserSexType)(sourceProperty.GetValue(sourceClass)
                                                 ?? UserSexType.Unknown);
            string valueName = await DialogManager.ShowComboBoxDialog(title,
                                                                      $"{enterName} '{element.StatTitle}'", localizedNames,
                                                                      oldValue.GetLocalizedName())
                               .ConfigureAwait(true);

            if (valueName == null)
            {
                return;
            }

            UserSexType value = UserSexType.Unknown.ParseLocalizedName <UserSexType>(valueName);

            //sourceProperty.SetValue(sourceClass, value.Length == 0 ? null : value);
            sourceProperty.SetValue(sourceClass, value);

            var request = await UserApi.EditProfile(
                SettingsManager.PersistentSettings.CurrentUser.Token,
                ViewModel.CurrentProfileData)
                          .ConfigureAwait(true);

            if (request.IsError)
            {
                await DialogManager.ShowErrorDialog(request.Message)
                .ConfigureAwait(true);

                sourceProperty.SetValue(sourceClass, oldValue);
            }

            var statBlock = element.TryFindParent <StackPanel>();

            if (statBlock == null)
            {
                return;
            }

            UpdateStatBlock(statBlock);
        }