Xamarin.Forms C#: как поместить значение в слайдер при загрузке страницыC#

Место общения программистов C#
Ответить
Anonymous
 Xamarin.Forms C#: как поместить значение в слайдер при загрузке страницы

Сообщение Anonymous »


I have some pages in my application.
From the "MainMenu Page" I can navigate to a "Configuration Page".
At the first time,in "MainMenu" I start the parameter "QuestionsToAsk" with 7.
When I call the "Configuration Page" I gave the parameter to the page, and I checked that the correct value is there.
But the Slider shows "1" as the value when the page is loaded.

I use VM to control all the code of the page.

On the XAML I have this code:






On the VM I have this code:

public class VMConfigurationPage : BaseViewModel
{
int maximum;
int questionsToAsk;

public VMConfigurationPage(INavigation navigation, int questionsToAsk)
{
Navigation = navigation;

Maximum = 40;
QuestionsToAsk = questionsToAsk;
}

public int Maximum
{
get { return maximum; }
set { SetValue(ref maximum, value); }
}
public int QuestionsToAsk
{
get { return questionsToAsk; }
set { SetValue(ref questionsToAsk, value); }
}
}

On the class "BaseModel" I have this code:

public class BaseViewModel : INotifyPropertyChanged
{
public INavigation Navigation;

public event PropertyChangedEventHandler PropertyChanged;
public void OnpropertyChanged([CallerMemberName] string nombre = "")
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nombre));
}

protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}

protected bool SetProperty(ref T field, T value, [CallerMemberName] string propertyName = null)
{
if (EqualityComparer.Default.Equals(field, value))
{
return false;
}

field = value;
OnPropertyChanged(propertyName);

return true;
}

private string _title;
public string Title
{
get { return _title; }
set
{
SetProperty(ref _title, value);
}
}

protected void SetValue(ref T backingFieled, T value, [CallerMemberName] string propertyName = null)
{
if (EqualityComparer.Default.Equals(backingFieled, value))
{
return;
}

backingFieled = value;

OnPropertyChanged(propertyName);
}
}

When I call the page, I gave a value (for example 7) to the parameter "questionsToAsk".
And I want to have the Slider with the value "7".
But the slider appears in the page with "1", not with the value that I gave to the page.

However, when I modify the Slider, the text shows the correct value. And the parameter "QuestionsToAsk" stores correctly the value of the Slider.

I tried changing the Mode in the Slider with:
`Value="{Binding QuestionsToAsk, Mode=OneWay}"`
And the Label shows "7", but the Slider has 1 as the value.

My problem is to start the value of the Slider at the beginning.

**Any idea about where is the error?**

I tried to change the "Mode".
I tried to use different parameters for the text and for the Slider.
But no results
Sorry for the code part, but I was not able to insert it correctly without the "br/>" tags.


Источник: https://stackoverflow.com/questions/780 ... -is-loaded
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «C#»