gpt4 book ai didi

c# - Xamarin 表单按钮 OnClick

转载 作者:行者123 更新时间:2023-11-30 20:20:11 25 4
gpt4 key购买 nike

目前我的项目中有一个 ContentPage.cs,使用 Xamarin Forms 作为工作环境,我只是想知道是否可以为代码末尾的按钮添加 OnClick。非常感谢任何帮助。提前致谢。

使用系统;

使用 Xamarin.Forms;

命名空间 DebuggerTestAndroidIOS{ 公共(public)类 VSParameters:ContentPage { 公共(public) VS 参数 () { 内容 = 新的 StackLayout { children = { 新的 StackLayout { BackgroundColor = Color.FromHex("0ADF80"), child = {

                        new Label { Text = PatientInformation.PatientName,
TextColor= Color.White,
FontSize = 25
}
}
},

//Patient Information Stack Layout
new StackLayout{ Orientation = StackOrientation.Horizontal,
Children = {

//Patient Image, sex and date of birth
new StackLayout{Orientation = StackOrientation.Vertical, Padding = new Thickness (30, 0, 0, 0),
Children = {

new Image {Source = "UserMale.png"},
new Label {Text = "Sex: " + PatientInformation.Sex , FontSize = 15, TextColor= Color.Black},
new Label{Text = "Date of Birth: " + (PatientInformation.DateOfBirth).ToString(), FontSize = 15, TextColor= Color.Black}
}

},

//other patient information
new StackLayout{Orientation = StackOrientation.Vertical,
Children = {
new Label {Text = "ID: " + PatientInformation.PatientID, FontSize = 15, TextColor= Color.Black},


new Label{Text = "Room: " + PatientInformation.RoomNumber, FontSize = 15, TextColor= Color.Black},
new Label {Text = "Bed: " + PatientInformation.BedID, FontSize = 15, TextColor= Color.Black},
new Label{Text = "Primary Doctor: " + PatientInformation.PrimaryDoctor, FontSize = 15, TextColor= Color.Black}

}

}


}
},
new StackLayout {Orientation = StackOrientation.Horizontal, Padding = new Thickness(30, 0, 0, 0),
Children = {

new StackLayout{Orientation = StackOrientation.Vertical,
Children = {
new Label {Text ="Heart Rate", FontSize= 20, TextColor = Color.FromHex("D95D65"), HorizontalOptions = LayoutOptions.StartAndExpand},
new Label{Text=""},
new Label {Text ="Temperature", FontSize= 20, TextColor = Color.FromHex("08CD78"), HorizontalOptions = LayoutOptions.StartAndExpand},
new Label{Text=""},
new Label {Text ="Respiration Rate", FontSize= 20, TextColor = Color.FromHex("08CD78"), HorizontalOptions = LayoutOptions.StartAndExpand},
new Label {Text ="Blood Pressure: ", FontSize= 20, TextColor = Color.FromHex("D95D65"), HorizontalOptions = LayoutOptions.StartAndExpand},
new Label{Text=""},
new Label{Text=""},
new Label {Text ="Systolic", FontSize= 18, TextColor = Color.FromHex("D95D65")},
new Label {Text ="Diastolic", FontSize= 18, TextColor = Color.FromHex("D95D65")}
}
},

new StackLayout{Orientation = StackOrientation.Vertical,
Children = {
new Entry {TextColor = Color.Black, BackgroundColor = Color.FromRgb(231, 231, 231), WidthRequest= 100},
new Entry {TextColor = Color.Black, BackgroundColor = Color.FromRgb(231, 231, 231), WidthRequest= 100},
new Entry {TextColor = Color.Black, BackgroundColor = Color.FromRgb(231, 231, 231), WidthRequest= 100},
new Label{Text=""},
new Label{Text=""},
new Label{Text=""},

new Entry {TextColor = Color.Black, BackgroundColor = Color.FromRgb(231, 231, 231), WidthRequest= 100},
new Entry {TextColor = Color.Black, BackgroundColor = Color.FromRgb(231, 231, 231), WidthRequest= 100},


}
},

}

},

new StackLayout{HorizontalOptions = LayoutOptions.Center,
Children = {

new Button{Text = "Add parameters"}


}

}
}
};

}
}

最佳答案

如果你真的想要内联,你可以这样做:

new Button {
Text = "Add parameters"
Command = new Command(() => {
//Fix world hunger here
})
};

关于c# - Xamarin 表单按钮 OnClick,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37353815/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com