예제 #1
0
        private async void EditNumericAge_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");

            int    oldValue = (int)(sourceProperty.GetValue(sourceClass) ?? 0);
            double?value    = await DialogManager.ShowNumericDialog(title,
                                                                    $"{enterName} '{element.StatTitle}'", Convert.ToDouble(oldValue),
                                                                    0.0, 255.0, 1.0, "F0")
                              .ConfigureAwait(true);

            if (value == null)
            {
                return;
            }

            //sourceProperty.SetValue(sourceClass, value.Length == 0 ? null : value);
            sourceProperty.SetValue(sourceClass, Convert.ToInt32(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);
        }
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            UIElementCollection result = null;
            int resultParameter        = 0;

            if (value is UIElementCollection collectionValue)
            {
                result = collectionValue;
            }

            if (result == null)
            {
                return(Visibility.Collapsed);
            }

            if (parameter is int intParameter)
            {
                resultParameter = intParameter;
            }

            for (int i = 0; i < result.Count - resultParameter; ++i)
            {
                UserProfileStat element = result[i] as UserProfileStat;

                if (element == null)
                {
                    continue;
                }

                if (element.Visibility == Visibility.Visible)
                {
                    return(Visibility.Visible);
                }
            }

            return(Visibility.Collapsed);
        }
예제 #3
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);
        }