我有一个简单的问题。如何使用FreshMvvm框架访问页面模型中的.xaml文件中的输入值?我希望在settings.cs构造函数中设置的默认值是用户在输入字段中输入的值。
谢谢!
testpage.xaml:
<Label Text="Set Server Address (FreshMvvm Binding):" />
<Entry Text="{Binding Settings.SyncServiceAddress}" Placeholder="Server IP Address" />
<Button Text="Sync Web Service - (FreshMvvm Binding)" Command="{Binding SyncButtonFreshMvvmBinding_Clicked}" />testpagemodel.cs:
public override void Init(object initData)
{
if (initData != null)
{
Settings = (Settings)initData;
}
else
{
Settings = new Settings();
}
}
public Command SyncButtonFreshMvvmBinding_Clicked
{
get
{
return new Command(async () =>
{
string serverAddress = Settings.SyncServiceAddress;
SyncService.PullNewXMLData(serverAddress);
await CoreMethods.PushPageModel<DashboardPageModel>();
});
}
}settings.cs:
public class Settings : ObservableObject
{
// Constructor
public Settings()
{
// Default value
SyncServiceAddress = "http://localhost/psm/service.aspx";
}
// Properties
public string SyncServiceAddress { get; set; }
public string UserIDSettings { get; set; }
}发布于 2018-04-13 06:00:00
记住,UI只需要知道一组有限的属性,所以可以在ViewModel中创建一个可绑定的属性,这样就不会试图绑定到嵌套属性。
在ViewModel中创建一个名为SyncServiceAddress的新字符串属性;
public string SyncServiceAddress
{
get{
return Settings.SyncServiceAddress;
}
set{
Settings.SyncServiceAddress = value;
}
}然后将您的XAML更新为以下内容。
<Entry Text="{Binding SyncServiceAddress}" Placeholder="Server IP Address" /> 这应该可以解决您的问题。
https://stackoverflow.com/questions/46653265
复制相似问题