如何在C#代码中更改框架样式?

huangapple go评论98阅读模式
英文:

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;
} 

huangapple
  • 本文由 发表于 2020年1月6日 17:37:17
  • 转载请务必保留本文链接:https://go.coder-hub.com/59609697.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定