简体   繁体   English

如何在 Xamarin Forms 中使用 HTML 和 CSS?

[英]How to use HTML and CSS in Xamarin Forms?

Do all UI designers use xaml syntax to design xamarin forms screens?是否所有 UI 设计师都使用 xaml 语法来设计 xamarin 表单屏幕? I'm learning mobile development and want to use html and css in Xamarin Forms.我正在学习移动开发并希望在 Xamarin Forms 中使用 html 和 css。 I don't know if I can.不知道能不能How to design professional xamarin forms screens?如何设计专业的 xamarin 表单屏幕? Thanks for your replies.感谢您的回复。

Do all of UI designers xamarin screen using xaml syntax?所有 UI 设计师都使用 xaml 语法进行 xamarin 筛选吗?

The answer is yes.答案是肯定的。

I'm learning mobile development and want to use html and css design on Xamarin Forms.我正在学习移动开发并希望在 Xamarin Forms 上使用 html 和 css 设计。 I don't know if I can.不知道能不能

It is not possible to use html and css as page designer in Xamarin projects.无法在 Xamarin 项目中使用 html 和 css 作为页面设计器。 If you really want to use html+css to develop mobile apps.如果你真的想使用 html+css 开发移动应用。 Cordova is a good option for you. Cordova是您不错的选择。

You could use XAML with CSS.您可以将 XAML 与 CSS 结合使用。 This is implented in Xamarin Forms since 2.6.0.自 2.6.0 起,这已在 Xamarin Forms 中实现。 All you need is to add CSS file to eg Asset folder in Xamarin Forms Shared project and load it in XAML in resource part.您只需要将 CSS 文件添加到 Xamarin Forms Shared 项目中的例如 Asset 文件夹,并在资源部分的 XAML 中加载它。

Write your CSS:编写你的 CSS:

^Label {
  color: blue;
}

^Entry {
    color: #ff0038;
}

#MyId {
    font-style: bold;
}

.FirstClass .SecondClass {
    font-size:6;
}

Load css file in XAML:在 XAML 中加载 css 文件:

<!-- set global style -->
<ContentPage.Resources>
   <StyleSheet Source="/Assets/styles.css" />
</ContentPage.Resources>

Set css classes in XAML:在 XAML 中设置 css 类:

 <StackLayout ClassId="FirstClass">
     <Entry ClassId="SecondClass"/>
     <Label StyleId="MyId" Text="This is a unique Text"/>
 </StackLayout>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM