我注意到,当在类似于BoxView的VisualElement上触发OnElementPropertyChanged时,底层平台视图的属性此时不会更新。
我想知道VisualElement的相应平台视图何时完成渲染,例如:
this.someBoxView.ViewHasRendered += (sender, e) => {
// Here I would know underlying UIView (in iOS) has finished rendering
};
查看Xamarin.Forms内部的一些代码,即VisualElementRenderer.cs,似乎OnPropertyChanged完成后可以引发一个事件。就像是:
protected virtual void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == VisualElement.BackgroundColorProperty.PropertyName)
SetBackgroundColor(Element.BackgroundColor);
else if (e.PropertyName == Layout.IsClippedToBoundsProperty.PropertyName)
UpdateClipToBounds();
else if (e.PropertyName == PlatformConfiguration.iOSSpecific.VisualElement.BlurEffectProperty.PropertyName)
SetBlur((BlurEffectStyle)Element.GetValue(PlatformConfiguration.iOSSpecific.VisualElement.BlurEffectProperty));
// Raise event
VisualElement visualElement = sender as VisualElement;
visualElement.ViewHasRendered();
}
Run Code Online (Sandbox Code Playgroud)
自然地,将事件添加到VisualElement类要复杂一些,因为需要将其子类化。但我认为您可以看到我的追求。
闲逛时,我注意到VisualElement上的属性,例如IsInNativeLayout。但这似乎只在Win / WP8中实现。另外,VisualElementRenderer上的UpdateNativeWidget也是如此,但是我无法弄清楚利用它们的正确方法。
有任何想法吗?非常感激。
我有一个使用ExecuteAsyncServiceRequest重载调用的方法,您会注意到这两个方法的主体是相似的。我发现自己想知道是否有更简洁的方式来编写这些方法?具体来说,不必在方法主体中重复自己。
提前致谢!
/// <summary>
/// Executes an async service request which returns a response of type TResponse
/// </summary>
/// <param name="execute">The service request to execute</param>
/// <param name="success">Callback when the service request is successful</param>
/// <param name="failure">Callback when the service request fails</param>
/// <typeparam name="TResponse">Type of the expected ServiceResult returned from the async request</typeparam>
protected async void ExecuteAsyncServiceRequest<TResponse>(Func<Task<ServiceResult<TResponse>>> execute,
Action<TResponse> success,
Action<string> failure)
{
ServiceResult<TResponse> result = await execute();
if (result.ResultCode == ServiceResult.ServiceResultCode.Failed)
failure(result.FailureDetails);
success(result.Response);
}
/// …Run Code Online (Sandbox Code Playgroud) 我不知所措,因为我必须遗漏一些东西.刚刚完成ASP.NET MVC 1.0(WROX),我试图实现一个执行简单搜索的视图,然后在表中呈现结果.然后,我希望能够通过结果页面.
所以我有一个来自ListingsController的搜索操作,从FormCollection获取一些值并相应地过滤结果:
//
//POST: /Listings/Search
// /Listings/Page/2
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Search(FormCollection collection,int? page)
{
var listings = listingRepository.GetListings();
//filter
if (collection["TypeOfHouse"] != null)
{
string[] typeList = collection["TypeOfHouse"].Split(',');
foreach (string type in typeList)
{
listings = from l in listings
where l.TypeOfHouse == type
select l;
}
}
//display the first page of results
int pageSize = 25;
var paginatedListings = new PriviledgeV1.Helpers.PaginatedList<Listing>(listings, 0, pageSize);
return View("Results", paginatedListings);
}
Run Code Online (Sandbox Code Playgroud)
最初,结果视图将使用第1页的前25条记录进行渲染.然后,我有一个处理"分页"的结果操作:
public ActionResult Results(int? page)
{
int pageSize = …Run Code Online (Sandbox Code Playgroud)