Margin, Height request and Width request is not applied for Label while converting the forms view to native view in Xamarin.Forms
#3,537 创建于 2018年8月10日
仓库指标
- 星标
- (5,644 个星标)
- PR 合并指标
- (30 天内没有已合并 PR)
描述
Description
Hi Team,
We are tried to convert the forms view to native view. But in this approach, given margin is not applied for the Label. We are loading Label inside a DataTemplate which is the property in Customview derived from Content view. Please refer the attached issue reproducing sample.
Custom View:
public class CustomView:ContentView
{
public CustomView()
{
}
public static readonly BindableProperty ContentTemplateProperty =
BindableProperty.Create("ContentTemplate", typeof(DataTemplate), typeof(CustomView), null, BindingMode.TwoWay);
public DataTemplate ContentTemplate
{
get { return (DataTemplate)GetValue(ContentTemplateProperty); }
set { SetValue(ContentTemplateProperty, value); }
}
}
Native view Conversion in Forms.UWP: internal static FrameworkElement ConvertFormsToNativeView(Xamarin.Forms.View view, CustomView formscustomView, int width, int height) { FrameworkElement native = null; var templateLayout = view as Xamarin.Forms.View; var renderer = ConvertToNative(templateLayout, formscustomView); native = renderer as FrameworkElement; templateLayout.Measure(width, height); templateLayout.Layout(new Xamarin.Forms.Rectangle(0, 0, width, height)); return native; }
Similarly we are converting in Xamarin.Forms.Android and Xamarin.Forms.iOS.
Mainpage.xaml: <ContentPage.Content> <local:CustomView x:Name="customView" HeightRequest="300" WidthRequest="300" IsVisible="True"> local:CustomView.ContentTemplate </local:CustomView.ContentTemplate> </local:CustomView> </ContentPage.Content>
Steps to Reproduce
- Run the attached sample.
- Note that given margin for label is not applied.
- Click the button to collapse the visibility of custom view.
Expected Behavior
Given margin must be applied to the label.
Actual Behavior
Given margin is not applied to the label.
Basic Information
- Version with issue: 2.4.0.280
- Platform Target Frameworks:
- iOS: 11.2, 11.4,11.9
- Android: 23, 24
- UWP: 14393
- Nuget Packages:2.4.0.280
- Affected Devices: all the devices