小编neq*_*opa的帖子

代码后面的绑定的 Xamarin 数据模板不起作用

我尝试在我的应用程序中创建一个页面,其中所有控件都是通过后面的 C# 代码动态生成的。我正在使用 Nuget 包DLToolkit, flowlist来创建流列表。

在使用Xaml之前,我已经在我的项目中使用了这个包,并且它完全可以工作。但是,当我尝试datatemplate在后面的代码中创建一个时,它只显示一个空白控件,但是当将鼠标悬停在该控件上方时,您可以看到其中实际上有项目。

我的问题是:如何在代码后面制作带有数据绑定的数据模板?

这是一个在Xaml中工作的示例:

<flv:FlowListView x:Name="flvList" BackgroundColor="White" FlowColumnCount="3" FlowItemsSource="{Binding LstItemSource}" HasUnevenRows="True">
            <flv:FlowListView.FlowColumnTemplate>
                <DataTemplate>

                    <StackLayout BackgroundColor="White" Padding="2" HorizontalOptions="FillAndExpand">

                        <Frame  Margin="20" Padding="0" HeightRequest="175" OutlineColor="Gray" BackgroundColor="White" CornerRadius="10" HasShadow="True" IsClippedToBounds="True">
                            <Frame.Content>

                                <AbsoluteLayout HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" >
                                    <Image Aspect="AspectFill" AbsoluteLayout.LayoutBounds="1,1,1,1" AbsoluteLayout.LayoutFlags="All"  Source="{Binding BgImage}" />
                                    <BoxView Color="Black" Opacity=".5"  AbsoluteLayout.LayoutBounds="1,1,1,1" AbsoluteLayout.LayoutFlags="All"/>
                                    <StackLayout Margin="20" VerticalOptions="CenterAndExpand" HorizontalOptions="CenterAndExpand">
                                        <Label Text="{Binding SubTitle}"  FontSize="Medium" TextColor="#66FFFFFF"/>
                                        <Label Text="{ Binding Title}" FontSize="Large" TextColor="White" />
                                    </StackLayout>
                                </AbsoluteLayout>

                            </Frame.Content>
                        </Frame>

                    </StackLayout>

                </DataTemplate>
            </flv:FlowListView.FlowColumnTemplate>
        </flv:FlowListView>
Run Code Online (Sandbox Code Playgroud)

但是,在这个项目中,控件是生成的,因此不涉及Xaml …

c# code-behind datatemplate xamarin xamarin.forms

1
推荐指数
1
解决办法
4575
查看次数

标签 统计

c# ×1

code-behind ×1

datatemplate ×1

xamarin ×1

xamarin.forms ×1