【发布时间】:2017-10-16 16:27:20
【问题描述】:
我正在使用来自 Xamarin 的名为“用于表单的 TableView”的示例来测试应用程序,并遇到了一个过时的部分 ImageSource = Device.OnPlatform 现在已替换为 switch 语句。这里没有问题并且有大量信息但是,我有一个特殊的问题并且看不到问题。
我正在添加的代码目前在下面的源代码中被注释掉,并且可以这样编译,当然没有图像。如果我删除注释部分,我会在第 35 行收到错误,缺少 }。 如果我突出显示最后一个中断正下方的花括号,它就会知道它的匹配,switch()。如果我突出显示正下方的开放花括号,它认为它是顶部的 Public SearchPage() 的一部分。 开关中的某些东西引起了问题,但我看不到它。
我希望有人遇到过这个问题并可能有答案。如果您需要更多详细信息,请告诉我。
using System;
using System.Collections.Generic;
using System.Text;
using Xamarin.Forms;
//using static System.Net.Mime.MediaTypeNames;
namespace MiddleMeeter
{
class SearchPage : ContentPage
{
public SearchPage()
{
Label header = new Label
{
Text = "TableView for a form",
FontSize = 30,
FontAttributes = FontAttributes.Bold,
HorizontalOptions = LayoutOptions.Center
};
TableView tableView = new TableView
{
Intent = TableIntent.Form,
Root = new TableRoot("TableView Title")
{
new TableSection("Table Section")
{
new TextCell
{
Text = "Text Cell",
Detail = "With Detail Text",
},
new ImageCell
{
/**********************************************************************************************
switch (Device.RuntimePlatform)
{
case Device.iOS:
ImageSource.FromUri(new Uri("http://xamarin.com/images/index/ide-xamarin-studio.png"));
break;
case Device.Android:
ImageSource.FromFile("waterfront.jpg");
break;
case Device.WinPhone:
ImageSource.FromFile("Images/waterfront.jpg");
break;
default:
ImageSource.FromFile("Images/waterfront.jpg");
break;
},
*///////////////////////////////////////////////////////////////////////////////////////////////
Text = "Image Cell",
Detail = "With Detail Text",
},
new SwitchCell
{
Text = "Switch Cell"
},
new EntryCell
{
Label = "Entry Cell",
Placeholder = "Type text here"
},
new ViewCell
{
View = new Label
{
Text = "A View Cell can be anything you want!"
}
}
},
}
};
// Build the page.
this.Content = new StackLayout
{
Children =
{
header,
tableView
}
};
}
}
}
【问题讨论】:
标签: xamarin xamarin.forms switch-statement imagesource