Xamarin Forms Contentpresenter Goes In Wrong Row And Empty On Phone
Solution 1:
I don't know what is the Frame
for, but it is currently covering the BoxView
and labels and thus made them invisible. Comment out the Frame
and you will see the labels and BoxView
again.
I believe I've done the XAML correctly, this is how I'd do it in WPF, it shows in the GroupBox.xaml Forms Previewer fine, but when I add it into the main page, the content of the Groupbox goes into the first row (the header) instead of the second for some reason within the Previewer.
ContentPresenter
doesn't work like that.In Xamarin.Forms, it is generally used in ControlTemplate
. For usage of ContentPresenter, please refer to this blog.
In your case, if you want to ContentPresenter to work. Instead of using Grid
for GroupBox
, you can use ContentView
for GroupBox
like below:
[XamlCompilation(XamlCompilationOptions.Compile)]
publicpartialclassGroupBox : ContentView
{
publicGroupBox()
{
InitializeComponent();
}
}
GroupBox.xaml:
<ContentViewxmlns="http://xamarin.com/schemas/2014/forms"xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"x:Class="Demo.GroupBox"><ContentView.ControlTemplate><ControlTemplate><Grid><Grid.RowDefinitions><RowDefinitionHeight="0.2*"/><RowDefinitionHeight="1*"/></Grid.RowDefinitions><!--<Frame Grid.Row="0" Grid.RowSpan="2" Margin="1" OutlineColor="AliceBlue"></Frame>--><BoxViewGrid.Row="0"BackgroundColor="Red"Margin="1" /><LabelGrid.Row="0"TextColor="White"Text="Label!"Margin="2" /><GridGrid.Row="1"><ContentPresenter/></Grid></Grid></ControlTemplate></ContentView.ControlTemplate>
Post a Comment for "Xamarin Forms Contentpresenter Goes In Wrong Row And Empty On Phone"