【发布时间】:2019-11-21 08:07:16
【问题描述】:
我是 Xamarin 和 UWP 的新手 - 尽管我们使用的是 Xamarin,但这个问题是关于 UWP 的。
我有一个资源字典 .xaml 文件。我需要创建这个文件的 c# 版本(不要问为什么,说来话长)。
基本上我有一些类似的东西......
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Style TargetType="Button">
<Setter Property="Background" Value="{ThemeResource SystemControlBackgroundBaseLowBrush}" />
<Setter Property="Foreground" Value="{ThemeResource SystemControlForegroundBaseHighBrush}" />
<Setter Property="BorderBrush" Value="{ThemeResource SystemControlForegroundTransparentBrush}" />
<Setter Property="BorderThickness" Value="0,0,0,2" />
<Setter Property="Padding" Value="12,8,12,8" />
<Setter Property="HorizontalAlignment" Value="Left" />
<Setter Property="VerticalAlignment" Value="Center" />
<Setter Property="FontFamily" Value="{ThemeResource ContentControlThemeFontFamily}" />
<Setter Property="FontWeight" Value="Normal" />
<Setter Property="FontSize" Value="{ThemeResource TextStyleLargeFontSize}" />
<Setter Property="UseSystemFocusVisuals" Value="False" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Grid x:Name="RootGrid"
...
是否有任何直接的方法可以创建与此 .xaml 文件等效的 c# 文件?
【问题讨论】:
-
将其解析为 XML?如果你愿意,你可以为它创建一个类型化的解析器。
-
不抱歉,我的意思是我需要创建继承自 UWP ResourceDictionary(我认为)的 ac# 类,然后添加相同的属性等。 - 创建我自己的自定义样式,但不要使用 XAML,而是使用C#。这甚至可能是不可能的,但据我所知,XAML 在幕后转换为 c# 类?谢谢