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

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

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

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

            return(result.GetLocalizedName());
        }
Exemplo n.º 3
0
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            UserPurposeType result = UserPurposeType.Unknown;

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

            return(result != UserPurposeType.Unknown
                ? Visibility.Visible
                : Visibility.Collapsed);
        }
Exemplo n.º 4
0
        private async void EditComboBoxPurpose_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>(UserPurposeType.Unknown.GetLocalizedNames());

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

            if (valueName == null)
            {
                return;
            }

            UserPurposeType value = UserPurposeType.Unknown.ParseLocalizedName <UserPurposeType>(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);
        }