英文:
How do I change the frame style in C# code?
问题
这很简单,但我搞不清楚。我有一个具有指定框架和其名称(Enter)的xml文件。如何在C#代码中为其添加样式(颜色、大小)?在MainPage类.xaml.cs中进行更改吗?感谢您的帮助!
// 在 MainPage.xaml.cs 中,您可以为 Frame 添加样式,如下所示:
using Xamarin.Forms;
namespace TaxiCity
{
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
// 设置 Frame 的背景颜色
Enter.BackgroundColor = Color.Blue;
// 设置 Frame 的大小
Enter.WidthRequest = 200;
Enter.HeightRequest = 100;
}
}
}
上述代码演示了如何在 MainPage.xaml.cs 中为名为 "Enter" 的 Frame 添加样式。您可以更改背景颜色、大小等属性,以根据您的需求自定义样式。
英文:
It's pretty simple, but I can't figure it out. I have an xml file with the specified frame and its name(Enter). How do I style it in C# code (color, size)? Make changes in the MainPage class.xaml.cs ? Thank you for your help !
ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
x:Class="TaxiCity.MainPage">
<Grid>
<Frame x:Name="Enter">
</Frame>
</Grid>
</ContentPage>
答案1
得分: 0
Agree with @FreakyAli , Since you have set the x:name of Frame , you can directly access it in Code behind .
{
InitializeComponent();
EnterFrame();
}
public void EnterFrame() {
Enter.BackgroundColor = Color.Red;
Enter.WidthRequest = 500;
Enter.HeightRequest = 500;
}
英文:
Agree with @FreakyAli , Since you have set the x:name of Frame , you can directly access it in Code behind .
public MainPage()
{
InitializeComponent();
EnterFrame();
}
public void EnterFrame() {
Enter.BackgroundColor = Color.Red;
Enter.WidthRequest = 500;
Enter.HeightRequest = 500;
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论