Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/xamarin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xamarin-XAML网格UI相互覆盖_Xaml_Xamarin_Xamarin.ios_Xamarin.forms_Xamarin Studio - Fatal编程技术网

Xamarin-XAML网格UI相互覆盖

Xamarin-XAML网格UI相互覆盖,xaml,xamarin,xamarin.ios,xamarin.forms,xamarin-studio,Xaml,Xamarin,Xamarin.ios,Xamarin.forms,Xamarin Studio,我正在使用我放在StackLayout中的Xamarin中的网格创建UI。 下面是xaml的以下代码 program.xaml <?xml version="1.0" encoding="UTF-8"?> <ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="LoginPage.Page"

我正在使用我放在StackLayout中的Xamarin中的网格创建UI。 下面是xaml的以下代码

program.xaml

<?xml version="1.0" encoding="UTF-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="LoginPage.Page">
    <ContentPage.Content>
        <StackLayout Orientation="Vertical">
            <StackLayout BackgroundColor="#3a4851">
                <Label Text="Identifications" TextColor="White" FontSize="15" Margin="10" />
            </StackLayout>
            <StackLayout>
                <Grid x:Name="identificationGridLayout" HorizontalOptions="Center"></Grid>
            </StackLayout>
            <StackLayout BackgroundColor="#3a4851">
                <Label Text="Deciles" TextColor="White" FontSize="15" Margin="10" />
            </StackLayout>
            <StackLayout>
                <Grid x:Name="decileGridLayout" HorizontalOptions="Center"></Grid>
            </StackLayout>
        </StackLayout>
    </ContentPage.Content>
</ContentPage>

我正在以编程方式创建网格标题和数据

program.cs

public partial class Page : ContentPage
{
    private LoadingPopUp popUp;
    private Repository repository = new Repository();
    private JObject jResult;
    private List<string> rowHeader;
    private List<PrescriberIdentitifcation> prescriberIdentificationValue;
    private List<PrescriberDecile> prescriberDecileValue;

    public Page() { InitializeComponent(); }

    public Page(string guid)
    {
        InitializeComponent();
        FetchDataForDetail(guid);
    }

    async void FetchDataForDetail(string guid)
    {
        try
        {
            popUp = new LoadingPopUp("Loading data ...");
            await PopupNavigation.PushAsync(popUp);
            //Get Identification Data for prescriber
            JObject identificationResult = await GetRepositoryDetailData(guid);

            var identificationdata = JsonConvert.DeserializeObject<PrescriberIdentificationList>(identificationResult.ToString());
            prescriberIdentificationValue = identificationdata.value;
            int index = 0;
            foreach (var obj in identificationResult["value"])
            {
                prescriberIdentificationValue[index].vcm_type_name = (string)obj["vcm_type@OData.Community.Display.V1.FormattedValue"];
                index++;
            }
            drawIdentificationGrid();

            //Get Deciles Data for prescriber
            JObject decileResult = await GetRepositoryDetailData(guid);
            var deciledata = JsonConvert.DeserializeObject<PrescriberIdentificationList>(decileResult.ToString());
            prescriberIdentificationValue = deciledata.value;
            Debug.WriteLine("data prescriberIdentificationValue : " + prescriberIdentificationValue);
            drawDecilesGrid();              
            await PopupNavigation.PopAllAsync();
        }
        catch (Exception ex) { 
            Debug.WriteLine("error in identification loading : " + ex.Message);
            await PopupNavigation.PopAllAsync();
        }

    }

    public async Task<JObject> GetRepositoryDetailData(string guid, string entity, string filter) 
    { 
        try
        {
            jResult = await repository.Retrieve(GlobalVariables.AuthToken, entity, filter + guid);
            return jResult;
        }
        catch (Exception err)
        {
            Debug.WriteLine(err.Message);
            await PopupNavigation.PopAllAsync();
            await DisplayAlert("Error", "Oops something went wrong", "Ok");
        }
        return jResult;
    }

    void drawIdentificationGrid()
    {
        try
        {
            rowHeader = new List<string>{"Type", "Number", "License State", "Sampleability","Expiration Date","License Status" };
            drawGridHeader(identificationGridLayout,1, rowHeader.Count,rowHeader);

            for (int rowIndex = 1; rowIndex <= prescriberIdentificationValue.Count; rowIndex++)
            {
              var datatypeLabel = new Label { Text = prescriberIdentificationValue[rowIndex-1].vcm_type_name.ToString(),FontSize=12, VerticalOptions = LayoutOptions.Center, HorizontalOptions = LayoutOptions.Center };
              var datanumberLabel = new Label { Text = prescriberIdentificationValue[rowIndex-1].vcm_name.ToString(),FontSize=12, VerticalOptions = LayoutOptions.Center, HorizontalOptions = LayoutOptions.Center };
              var datalicenseStateLabel = new Label { Text = (prescriberIdentificationValue[rowIndex-1]._vcm_licensestate_value != null) ? prescriberIdentificationValue[rowIndex-1]._vcm_licensestate_value : "-" , FontSize=12, VerticalOptions = LayoutOptions.Center, HorizontalOptions = LayoutOptions.Center };
              var datasampleabiltiyLabel = new Label { Text = (prescriberIdentificationValue[rowIndex - 1].vcm_sampleability == false) ? "No": "Yes", FontSize=12, VerticalOptions = LayoutOptions.Center, HorizontalOptions = LayoutOptions.Center };
              var dataexpirationDateLabel = new Label { Text = (prescriberIdentificationValue[rowIndex-1].vcm_expirationdate != null) ? prescriberIdentificationValue[rowIndex-1].vcm_expirationdate : "-", FontSize=12, VerticalOptions = LayoutOptions.Center, HorizontalOptions = LayoutOptions.Center };
              Debug.WriteLine("data datatypeLabel {0} datanumberLabel {1} datalicenseStateLabel {2} datasampleabiltiyLabel {3} dataexpirationDateLabel {4} rowIndex {5}",datatypeLabel.Text,datanumberLabel.Text,datalicenseStateLabel.Text, datasampleabiltiyLabel.Text, dataexpirationDateLabel.Text, rowIndex);

              identificationGridLayout.Children.Add(datatypeLabel, 0, rowIndex);
              identificationGridLayout.Children.Add(datanumberLabel, 1, rowIndex);
              identificationGridLayout.Children.Add(datalicenseStateLabel, 2, rowIndex);
              identificationGridLayout.Children.Add(datasampleabiltiyLabel, 3, rowIndex);      
              identificationGridLayout.Children.Add(dataexpirationDateLabel, 4, rowIndex);

            }

        }
        catch (Exception ex) { Debug.WriteLine("Error in drawing Identifications: "+ ex.Message);}

    }

    void drawDecilesGrid()
    {
        try
        {
            rowHeader = new List<string>{"Quarter", "Decile Type", "Decile", "Rank","Organization Type" };
               drawGridHeader(decileGridLayout,1, rowHeader.Count, rowHeader);

            //for (int rowIndex = 1; rowIndex <= prescriberIdentificationValue.Count; rowIndex++)
            //{
            //  var datatypeLabel = new Label { Text = prescriberIdentificationValue[rowIndex - 1].vcm_type_name.ToString(), FontSize = 12, VerticalOptions = LayoutOptions.Center, HorizontalOptions = LayoutOptions.Center };
            //  var datanumberLabel = new Label { Text = prescriberIdentificationValue[rowIndex - 1].vcm_name.ToString(), FontSize = 12, VerticalOptions = LayoutOptions.Center, HorizontalOptions = LayoutOptions.Center };
            //  var datalicenseStateLabel = new Label { Text = (prescriberIdentificationValue[rowIndex - 1]._vcm_licensestate_value != null) ? prescriberIdentificationValue[rowIndex - 1]._vcm_licensestate_value : "-", FontSize = 12, VerticalOptions = LayoutOptions.Center, HorizontalOptions = LayoutOptions.Center };
            //  var datasampleabiltiyLabel = new Label { Text = (prescriberIdentificationValue[rowIndex - 1].vcm_sampleability == false) ? "No" : "Yes", FontSize = 12, VerticalOptions = LayoutOptions.Center, HorizontalOptions = LayoutOptions.Center };
            //  var dataexpirationDateLabel = new Label { Text = (prescriberIdentificationValue[rowIndex - 1].vcm_expirationdate != null) ? prescriberIdentificationValue[rowIndex - 1].vcm_expirationdate : "-", FontSize = 12, VerticalOptions = LayoutOptions.Center, HorizontalOptions = LayoutOptions.Center };
            //  Debug.WriteLine("data datatypeLabel {0} datanumberLabel {1} datalicenseStateLabel {2} datasampleabiltiyLabel {3} dataexpirationDateLabel {4} rowIndex {5}",datatypeLabel.Text,datanumberLabel.Text,datalicenseStateLabel.Text, datasampleabiltiyLabel.Text, dataexpirationDateLabel.Text, rowIndex);
            //  identificationGridLayout.Children.Add(datatypeLabel, 0, rowIndex);
            //  identificationGridLayout.Children.Add(datanumberLabel, 1, rowIndex);
            //  identificationGridLayout.Children.Add(datalicenseStateLabel, 2, rowIndex);
            //  identificationGridLayout.Children.Add(datasampleabiltiyLabel, 3, rowIndex);
            //  identificationGridLayout.Children.Add(dataexpirationDateLabel, 4, rowIndex);

            //}

        }
        catch (Exception ex) { Debug.WriteLine("Error in drawing Identifications: "+ ex.Message);}
    }

    void drawGridHeader(Grid gridLayout, int rowIndexLength, int columnIndexLength, List<string> rowHeaders)
    {
        try
        {
            gridLayout.RowDefinitions = new RowDefinitionCollection();
            gridLayout.ColumnDefinitions = new ColumnDefinitionCollection();

            for (int rowIndex = 0; rowIndex < rowIndexLength; rowIndex++)
            {
                gridLayout.RowDefinitions.Add(new RowDefinition());
            }
            for (int columnIndex = 0; columnIndex <= columnIndexLength; columnIndex++)
            {
                gridLayout.ColumnDefinitions.Add(new ColumnDefinition());
            }

            for (int i = 0; i < columnIndexLength; i++)
            {
                var label = new Label { Text = rowHeaders[i], FontSize = 14, VerticalOptions = LayoutOptions.Center, HorizontalOptions = LayoutOptions.Center };
                identificationGridLayout.Children.Add(label, i, 0);
            }

        }
        catch (Exception ex) { Debug.WriteLine("Error in drawing grid header: "+ ex.Message);}
    }
}
public分部类页面:ContentPage
{
私有加载弹出窗口;
私有存储库=新存储库();
私人作业项目jResult;
私有列表行标题;
私有列表规定了标识值;
私人列表规定了CILEVALUE;
公共页(){InitializeComponent();}
公共页(字符串guid)
{
初始化组件();
FetchDataForDetail(guid);
}
异步void FetchDataForDetail(字符串guid)
{
尝试
{
popUp=新加载popUp(“加载数据…”);
等待PopupNavigation.PushAsync(弹出窗口);
//获取处方医生的识别数据
JObject identificationResult=等待GetRepositoryDetailData(guid);
var identificationdata=JsonConvert.DeserializeObject(identificationResult.ToString());
PrescriptiveIdentificationValue=identificationdata.value;
int指数=0;
foreach(identificationResult[“值”]中的var obj)
{
PrescriptiveIdentificationValue[索引].vcm_type_name=(字符串)obj[“vcm_type@OData.Community.Display.V1.FormattedValue"];
索引++;
}
drawIdentificationGrid();
//获取处方医生的十进制数据
JObject decileResult=等待GetRepositoryDetailData(guid);
var deciledata=JsonConvert.DeserializeObject(DecilerResult.ToString());
PrescriptiveIdentificationValue=deciledata.value;
Debug.WriteLine(“数据PrescribedIdentificationValue:+PrescribedIdentificationValue”);
drawDecilesGrid();
等待PopupNavigation.PopAllAsync();
}
捕获(例外情况除外){
Debug.WriteLine(“标识加载错误:“+ex.Message”);
等待PopupNavigation.PopAllAsync();
}
}
公共异步任务GetRepositoryDetailData(字符串guid、字符串实体、字符串筛选器)
{ 
尝试
{
jResult=await repository.Retrieve(GlobalVariables.AuthToken,entity,filter+guid);
返回jResult;
}
捕获(异常错误)
{
Debug.WriteLine(错误消息);
等待PopupNavigation.PopAllAsync();
等待显示警报(“错误”,“哦,出了点问题”,“确定”);
}
返回jResult;
}
void drawIdentificationGrid()
{
尝试
{
rowHeader=新列表{“类型”、“编号”、“许可证状态”、“可抽样性”、“到期日期”、“许可证状态”};
drawGridHeader(identificationGridLayout,1,rowHeader.Count,rowHeader);

对于
drawGridHeader()
中最后一个for循环内的(int-rowIndex=1;rowIndex),添加标签时没有引用传入的网格:

for (int i = 0; i < columnIndexLength; i++)
{
    var label = new Label { Text = rowHeaders[i], FontSize = 14, VerticalOptions = LayoutOptions.Center, HorizontalOptions = LayoutOptions.Center };
    // This references the wrong Grid
    // identificationGridLayout.Children.Add(label, i, 0);
    gridLayout.Children.Add(label, i, 0);
}
for(int i=0;i
完全同意。我怎么会错过那张支票。谢谢@Jon
for (int i = 0; i < columnIndexLength; i++)
{
    var label = new Label { Text = rowHeaders[i], FontSize = 14, VerticalOptions = LayoutOptions.Center, HorizontalOptions = LayoutOptions.Center };
    // This references the wrong Grid
    // identificationGridLayout.Children.Add(label, i, 0);
    gridLayout.Children.Add(label, i, 0);
}