繁体   English   中英

Xamarin Forms 如何将 ContentPage 注入 Frame 元素?

[英]Xamarin Forms How can I inject a ContentPage into Frame element?

我需要将 ContentPage 注入 Frame 元素吗?

这有可能做到吗?

我已经更新了我的描述并添加了以下代码

XAML 代码

<navigationdrawer:SfNavigationDrawer x:Name="navigationDrawer" 
                                         DrawerWidth ="400" 
                                         Position="Right"
                                         BackgroundColor="{DynamicResource DynamicContentPageBackgroundColor}"
                                         DrawerHeaderHeight="160">
        <navigationdrawer:SfNavigationDrawer.ContentView>

            <Grid x:Name="mainContentView" BackgroundColor="{DynamicResource DynamicContentPageBackgroundColor}">
                <Grid.RowDefinitions>
                    <RowDefinition Height="auto"/>
                    <RowDefinition/>
                </Grid.RowDefinitions>
                <StackLayout BackgroundColor="{DynamicResource DynamicContentPageBackgroundColor}" Orientation="Horizontal">
                    <controls:IconButton  Text="{i18n:TransIcn HamburgerMenu}" FontSize="30" x:Name="SyncIcon"  HorizontalOptions="Start"  Clicked="hamburgerButton_Clicked" BackgroundColor="Transparent" TextColor="#FFFFFF" ></controls:IconButton>
                    <Label x:Name="headerLabel"  HorizontalTextAlignment="Center" VerticalTextAlignment="Center" Text="" FontSize="16"/>
                </StackLayout>

                <ScrollView Grid.Row="1" Margin="0" Padding="0">
                    <Frame x:Name="contentViewFrame" >
                    </Frame>
                </ScrollView>
            </Grid>
        </navigationdrawer:SfNavigationDrawer.ContentView>
        <navigationdrawer:SfNavigationDrawer.DrawerHeaderView>
            <Grid BackgroundColor="{DynamicResource DynamicContentPageBackgroundColor}">
                <Grid.RowDefinitions>
                    <RowDefinition Height="120"/>
                    <RowDefinition Height="40"/>
                </Grid.RowDefinitions>
                <!--<Image Source="icon.png" HeightRequest="110"  BackgroundColor="#1aa1d6" VerticalOptions="Center" HorizontalOptions="Center"/>-->
                <Label Text="James Pollock" Grid.Row="1" HorizontalTextAlignment="Center" HorizontalOptions="Center" FontSize="20" TextColor="White"/>
            </Grid>
        </navigationdrawer:SfNavigationDrawer.DrawerHeaderView>
        <navigationdrawer:SfNavigationDrawer.DrawerContentView>
            <ListView x:Name="listView"
                      FlowDirection="RightToLeft"
                      ItemsSource="{Binding Items}"
                      BackgroundColor="{DynamicResource DynamicContentPageBackgroundColor}"
                      ItemSelected="listView_ItemSelected">
                <ListView.ItemTemplate>
                    <DataTemplate>
                        <ViewCell>
                            <StackLayout Orientation="Horizontal" Margin="0,8,0,0"  BackgroundColor="{DynamicResource DashboardItemsDarkSurface}">
                                <Label Text="{Binding IconText}"  HorizontalOptions="Start" FontSize="30" Style="{StaticResource EventaIconStyle}" ></Label>
                                <Label  Text="{Binding Title}" HorizontalOptions="Start" Style="{StaticResource MainHeaderLabel}"></Label>
                            </StackLayout>
                        </ViewCell>
                    </DataTemplate>
                </ListView.ItemTemplate>
            </ListView>
        </navigationdrawer:SfNavigationDrawer.DrawerContentView>
        <navigationdrawer:SfNavigationDrawer.DrawerFooterView>
            <Grid BackgroundColor="{DynamicResource DynamicContentPageBackgroundColor}" >
                <StackLayout VerticalOptions="Center" 
            `enter code here`         HorizontalOptions="Center">
                    <Label Text="Footer View"/>
                </StackLayout>
            </Grid>
        </navigationdrawer:SfNavigationDrawer.DrawerFooterView></navigationdrawer:SfNavigationDrawer>

如果您需要更多信息,请告诉我。

问题是我无法将 ContentPage Object 添加到 ContentView 项目中,所以请提供一些解决方法,我可能会使用 go 吗?

正如他们在关于内容视图与内容页面的评论中提到的那样,这应该对您有用,只需稍作改动。 当我编写我的第一个 Xamarin 应用程序时,随着时间的推移,我有几个其他应用程序在控件中有嵌套控件并且不想发现自己处于类似状态。

所以,我所做的就是创建简单的用户控件,其中包含我需要的所有东西。 因此,当我创建页面时,我只需将用户控件添加到实际需要放置的位置。 这样,如果我需要更改该用户控件的布局,它不会更改 rest 的功能。 绑定是相同的,因为绑定上下文是同一级别,无论控件的视觉深度如何。

因此,如果您要为其自己的上下文创建一个新的导航抽屉用户控件,那么在您的内容页面中添加它应该适合您。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM