XAML 中 CSS 的等效项 [英] Equivalent of CSS in XAML

查看:27
本文介绍了XAML 中 CSS 的等效项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Web 开发中,样式表非常常用.在 Swing 中有用于处理 GUI 的布局管理器.我认为 XAML 应用了这些范式之一的假设是否正确?两个都?在这种情况下,首选哪一个?

In web development, styles sheets are very commonly used. In Swing there are layout managers for handling of the GUI. Am I correct in the assumption that XAML applies one of those paradigms? Both? Which one is preferred in such case?

我已经检查了 Intellisense,但除了 Style 字段之外,我没有发现任何特别明显的东西,而且我不清楚要 google 搜索哪些关键字.建议?

I've checked Intellisense but except for the Style field, I didn't find anything particularly obvious and I'm unclear what keywords to google for. Suggestions?

推荐答案

将样式作为资源存储在程序集中的更好方法,以便它可以作为 css 出现在多个文件中

Better way to store style as a resource in the assembly so that it can be available in multiple files as css

您可以查看:Silverlight 和样式

还要检查:如何通过设置 Silverlight 控件样式应用程序资源

将这样的样式放在 Application.Xaml 文件中或为您创建一个新样式

put style like this in Application.Xaml file or create new one for you

<Application xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
             x:Class="AppResStyle.App"
             >
    <Application.Resources>
        <Style x:Key="ButtonStyle" TargetType="Button">
            <Setter Property="BorderBrush" Value="Green" />
            <Setter Property="Foreground" Value="Blue" />
     </Style>
    </Application.Resources>
</Application>

现在您可以在多个 uercontrol 中使用这样的方式为按钮指定样式

Now you can utilize like this in multiple uercontrol to assign style to button

<UserControl x:Class="AppResStyle.Page"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    Width="130" Height="80">
    <Grid x:Name="LayoutRoot" Background="White">
        <Button Content="Button1" Height="75" Width="125" Style="{StaticResource ButtonStyle}" />
    </Grid>
</UserControl>

这篇关于XAML 中 CSS 的等效项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆