Xamarin.Forms在调试模式下可以正常显示列表数据,但在发布模式下无法显示。

3

我有一段代码,它将数据以列表的形式在Xamarin Form中显示。在调试模式下,它可以正常显示,但是在发布模式或APK中,则无法在列表中显示任何内容。在发布模式下,列表中只显示静态按钮。 以下是我在表单中编写的代码。请问是否有人可以指导我解决这个问题。

<StackLayout>
    <ListView Grid.Row="1" x:Name="listLogin" ItemsSource="{Binding callLogList}">
        <ListView.ItemTemplate>
            <DataTemplate>
                <ViewCell>
                    <ViewCell.View>
                        <Grid x:Name="Item">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto"/>
                                <ColumnDefinition Width="Auto"/>
                            </Grid.ColumnDefinitions>
                            <Image Grid.Column="1" x:Name="ImgCallType" Source="{Binding ImageUrl}" Style="{Binding width:50px,height:50px;}"></Image>
                            <Label Grid.Column="2" FontSize="Subtitle" Text="{Binding Mobilenumber}"></Label>
                            <Label Grid.Column="3" FontSize="Subtitle" Text="12345"></Label>
                            <Button  Grid.Column="4"  Text="Add"  TextColor="Black"   HorizontalOptions="EndAndExpand" Clicked="" CommandParameter="{Binding Mobilenumber}"/>
                        </Grid>
                    </ViewCell.View>
                </ViewCell>
            </DataTemplate>
        </ListView.ItemTemplate>
    </ListView>
</StackLayout>

public partial class MiscallData : ContentPage
    {
        public MiscallData()
        {
            InitializeComponent();
            GetCallLogs();
        }
        public void GetCallLogs()
        {
            Android.Content.Context myContext = Android.App.Application.Context;

            string OutgoingqueryFilter = string.Format("{0}={1}", CallLog.Calls.Type, (int)CallType.Outgoing);
            string querySorter = string.Format("{0} desc ", CallLog.Calls.Date);

            ICursor OutgoingqueryData = myContext.ContentResolver.Query(CallLog.Calls.ContentUri, null, null, null, querySorter);
            List<MisscallDataModel> callLogList = new List<MisscallDataModel>();

            while (OutgoingqueryData.MoveToNext())
            {
                MisscallDataModel model = new MisscallDataModel();

                //---phone number---
                model.Mobilenumber = OutgoingqueryData.GetString(OutgoingqueryData.GetColumnIndex(CallLog.Calls.Number));

                //---date of call---
                int secondindex = OutgoingqueryData.GetColumnIndex(CallLog.Calls.Date);
                long seconds = OutgoingqueryData.GetLong(secondindex);
                SimpleDateFormat formatter = new SimpleDateFormat("dd-MM-yy HH:mm");
                String dateString = formatter.Format(new Date(seconds));
                model.Date = dateString;
                model.ImageUrl = "BlockCall.png";
                callLogList.Add(model);
            }
            listLogin.ItemsSource = callLogList;
        }
    }

public class MisscallDataModel
    {
        public long UserId { get; set; }
        public string Mobilenumber { get; set; }
        public string Date { get; set; }
        public string callType { get; set; }
        public string ImageUrl { get; set; }

    }

确保您设置了读取通话记录的权限! - N Subedi
1个回答

4

我自己解决了我的问题,代码没有任何问题,只是设置属性的问题, 只需转到Android属性,然后选择Android选项,在那里找到链接器属性,选择无选项即可。

Android项目 => 属性 => Android选项 => 链接器属性 => 链接 => 无。


1
这些都是关于发布模式的内容。最终你找到了答案,干得好。 - Naveen
谢谢分享。我也遇到了与其他类型元素绑定的相同问题。 - Belight
注意:我还不得不删除PCL和Android项目中的所有OBJ和BIN文件,以强制重新构建解决方案! - Belight
MAUI的解决方案是什么? - undefined

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接