如何在不同类型的项目中使用视图模型
How to use the viewmodel with different types of projects
我有一个相当复杂的项目,包含多个子项目。
- 申请
- WPF 应用程序
- Windows 应用商店
- Windows Phone 应用
- 合同
- 服务合同(WPF 的 WCF)
- 服务控制器(windows phone 的 WebAPI)
- 基础设施(EventAggregator/Prism)
- ViewModels(最好由 WPF、Windows Phone 和 Windows App 使用)
- 视图(特定于 WPF)
只要我专注于WPF,我就没有问题。在我的视图模型中,我可以调用网络服务并用所需的数据填充它。对于 Windows Phone/Windows Store App 我不能总是使用 WCF。但是视图模型保持不变。我如何 "send" 对我的视图模型进行正确的服务调用?
public async override Task<object> RetrieveItems()
{
if ((Customer != null))
{
return await Task.Run(() => Current.ApplicationService.Schedule_Appointments_GetItems_By_Relation(Customer.Relation_ID));
}
else
{
return null;
}
}
只要它是一个 wcf 服务,这个函数就可以正常工作。
是否有可能根据使用此视图模型的视图更改此功能?
这是一个视图模型的完整代码:
namespace ISynergy.Modules.Relations
{
public class Customer_Activities_ViewModel : Customer_Base_ViewModel
{
public Customer_Activities_ViewModel()
: base()
{
}
public override void Add()
{
throw new NotImplementedException();
}
public override Task Delete(object vItem)
{
throw new NotImplementedException();
}
public override void Edit(object vItem)
{
throw new NotImplementedException();
}
public async override Task<object> RetrieveItems()
{
if ((Customer != null))
{
return await Task.Run(() => Current.ApplicationService.Schedule_Appointments_GetItems_By_Relation(Customer.Relation_ID));
}
else
{
return null;
}
}
}
}
当然同样适用于其他覆盖procedures/functions(添加,删除和编辑)
好的,我想我得到了答案。
我任何人有建议或意见请免费提供一个。
也许这个答案可以帮助其他人解决同样的问题。
解决方案包括两个调整。
public async override Task<object> RetrieveItems()
{
if ((Customer != null))
{
return await Task.Run(GetItems_Action);
//return await Task.Run(() => Current.ApplicationService.Schedule_Appointments_GetItems_By_Relation(Customer.Relation_ID));
}
else
{
return null;
}
}
并添加下一行以允许从视图中进行调整。
public Action Add_Action;
public Action<object> Edit_Action;
public Func<object, Task> Delete_Action;
public Func<Task<object>> GetItems_Action;
我有一个相当复杂的项目,包含多个子项目。
- 申请
- WPF 应用程序
- Windows 应用商店
- Windows Phone 应用
- 合同
- 服务合同(WPF 的 WCF)
- 服务控制器(windows phone 的 WebAPI)
- 基础设施(EventAggregator/Prism)
- ViewModels(最好由 WPF、Windows Phone 和 Windows App 使用)
- 视图(特定于 WPF)
只要我专注于WPF,我就没有问题。在我的视图模型中,我可以调用网络服务并用所需的数据填充它。对于 Windows Phone/Windows Store App 我不能总是使用 WCF。但是视图模型保持不变。我如何 "send" 对我的视图模型进行正确的服务调用?
public async override Task<object> RetrieveItems()
{
if ((Customer != null))
{
return await Task.Run(() => Current.ApplicationService.Schedule_Appointments_GetItems_By_Relation(Customer.Relation_ID));
}
else
{
return null;
}
}
只要它是一个 wcf 服务,这个函数就可以正常工作。 是否有可能根据使用此视图模型的视图更改此功能?
这是一个视图模型的完整代码:
namespace ISynergy.Modules.Relations
{
public class Customer_Activities_ViewModel : Customer_Base_ViewModel
{
public Customer_Activities_ViewModel()
: base()
{
}
public override void Add()
{
throw new NotImplementedException();
}
public override Task Delete(object vItem)
{
throw new NotImplementedException();
}
public override void Edit(object vItem)
{
throw new NotImplementedException();
}
public async override Task<object> RetrieveItems()
{
if ((Customer != null))
{
return await Task.Run(() => Current.ApplicationService.Schedule_Appointments_GetItems_By_Relation(Customer.Relation_ID));
}
else
{
return null;
}
}
}
}
当然同样适用于其他覆盖procedures/functions(添加,删除和编辑)
好的,我想我得到了答案。 我任何人有建议或意见请免费提供一个。 也许这个答案可以帮助其他人解决同样的问题。
解决方案包括两个调整。
public async override Task<object> RetrieveItems()
{
if ((Customer != null))
{
return await Task.Run(GetItems_Action);
//return await Task.Run(() => Current.ApplicationService.Schedule_Appointments_GetItems_By_Relation(Customer.Relation_ID));
}
else
{
return null;
}
}
并添加下一行以允许从视图中进行调整。
public Action Add_Action;
public Action<object> Edit_Action;
public Func<object, Task> Delete_Action;
public Func<Task<object>> GetItems_Action;