我对Xamarin.Forms和c#完全陌生,如果这是个愚蠢的问题,请原谅我。我必须创建一个带有某些条目和选择器的页面,并使用输入的值来设置对象覆盖的属性。这是我的封面对象:
public class Cover
{
public enum Categories { Brasses, Percussions, Keyboards, Strings, Voices, Woodwinds, Other };
public User administrator { get; private set; }
public List<Track> tracks { get; private set; }
public String title { get; private set; }
public String author { get; private set; }
public String note { get; private set; }
public Boolean collaborative;
public Categories category;
public Cover(User administrator, String title, String author, String note, Categories category, Boolean collaborative, List<Track> tracks = null)
{
this.administrator = administrator;
this.tracks = tracks == null ? new List<Track>() : tracks;
this.title = title;
this.author=author;
this.category = category;
this.collaborative = collaborative;
}
public Cover() { }这是我的页面:
public createCover()
{
var userTest = new User("SmartPerson", "", null, null);
var entryTitle = new Entry
{
Placeholder = " ",
Keyboard = Keyboard.Text,
};
var entryAuthor = new Entry
{
Placeholder = " ",
Keyboard = Keyboard.Text,
};
var editorNote = new Editor
{
Text = "Ex: Metal Cover of the Super Mario main theme!",
FontSize = 10,
Keyboard = Keyboard.Text,
};
var pickerCategory = new Picker
{
Title = "Category",
VerticalOptions = LayoutOptions.Center
};
var categories = new List<string> { "Blues", "Country", "Dance", "Hip-Hop", "Jazz", "Metal", "Pop", "Rap", "Reggae", "Rock", "Classical", "Soundtracks", "Videogames", "Instrumental", "Anime", "Dubstep"};
foreach (string categoryName in categories)
{
pickerCategory.Items.Add(categoryName);
}
var collaborateSwitch = new Switch
{
HorizontalOptions = LayoutOptions.Center,
VerticalOptions = LayoutOptions.CenterAndExpand
};
var collaborate = new Label
{
Text = "Do you want other musicians to collaborate with you?",
FontSize = 15,
HorizontalOptions = LayoutOptions.Start,
};
var ok = new Button
{
Text = "Ok",
FontSize = Device.GetNamedSize(NamedSize.Medium, typeof(Button)),
HorizontalOptions = LayoutOptions.Center,
};
ok.Clicked += OnOkClicked;
var stack = new StackLayout
{
Children =
{
entryTitle,
entryAuthor,
editorNote,
pickerCategory,
collaborate,
collaborateSwitch,
ok,
},
};
var scrollView = new ScrollView
{
VerticalOptions = LayoutOptions.FillAndExpand,
Content = stack
};
Content = scrollView;
this.Padding = new Thickness(20);
this.BindingContext = new Cover();
}
private void OnOkClicked(object sender, EventArgs e)
{
///???
}
}
}我想要的是当单击Ok Button时,对象覆盖被创建,所有这些条目值都是属性(所以entryTitle.TextProperty应该填充盖的标题属性,等等),但我只是找不到一种方法来实现它。只有当Ok si单击时,我才需要创建对象。谢谢你的帮助
发布于 2016-11-28 22:06:37
没有问题是愚蠢的!!
你的掩护对象没问题。
但是,您在业务逻辑中使用页面后面的代码的方法不是。这是一个兔子洞,在你的程序发展过程中有很多问题。
模式是一种强烈推荐的Xamarin表单开发方法。我可以建议你在press/2016/03/31/free-ebook-creating-mobile-apps-with-xamarin-forms/下载并阅读Petzold的免费书籍吗?
我相信,如果您采用MVVM方法,您将更加清楚地回答您的问题。
https://stackoverflow.com/questions/40850146
复制相似问题