- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我找到了一些 evidence这是可能的,
self.scene = Canvas()
Application.LoadComponent(self.scene, Uri('app.xaml', UriKind.Relative))
但是我的代码失败了:
class Program
{
[STAThread]
static void Main(string[] args)
{
Canvas scene = new Canvas();
Application.LoadComponent(scene, new Uri("app.xaml", UriKind.Relative));
}
}
我使用相同的 app.xaml 和“Build Action: None”和“Copy always”。
<Canvas
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="System.Windows.Controls.Canvas"
x:Name="ball_design" >
<Canvas x:Name="workaround_canvas" >
<TextBlock x:Name="fps" Canvas.Left="10" Canvas.Top="10" Height="40" Canvas.ZIndex="10000" Text="-- fps" />
<Canvas x:Name="wpfe_ball_0" Width="52" Height="52" Canvas.Left="0" Canvas.Top="30">
<!-- Layer 3/<Group>/<Path> -->
<Path Opacity="0.900000" StrokeThickness="2.000000" Stroke="#ffa6d000" StrokeMiterLimit="1.000000" Fill="#ffcbff00" Data="F1 M 51.000000,26.000000 C 51.000000,39.806641 39.807129,51.000000 26.000000,51.000000 C 12.192871,51.000000 1.000000,39.806641 1.000000,26.000000 C 1.000000,12.193359 12.192871,1.000000 26.000000,1.000000 C 39.807129,1.000000 51.000000,12.193359 51.000000,26.000000 Z"/>
<!-- Layer 3/<Group>/<Path> -->
<Path Opacity="0.740000" Data="F1 M 43.143066,13.087891 C 50.602051,22.888672 49.009766,36.642578 39.590332,43.812500 C 30.170898,50.980469 16.489258,48.842773 9.032715,39.042969 C 1.573242,29.240234 3.166016,15.486328 12.584961,8.316406 C 22.003906,1.149414 35.685547,3.285156 43.143066,13.087891 Z">
<Path.Fill>
<RadialGradientBrush MappingMode="Absolute" GradientOrigin="156.791016,170.453125" Center="156.791016,170.453125" RadiusX="53.626404" RadiusY="53.626404">
<RadialGradientBrush.GradientStops>
<GradientStop Offset="0.000000" Color="#ffffffff"/>
<GradientStop Offset="0.361685" Color="#fff5f7dd"/>
<GradientStop Offset="0.415730" Color="#ffebf0bc"/>
<GradientStop Offset="1.000000" Color="#ffcbff00"/>
</RadialGradientBrush.GradientStops>
<RadialGradientBrush.Transform>
<MatrixTransform Matrix="1.190000,0.165000,-0.165000,-1.281300,-113.414185,241.757843" />
</RadialGradientBrush.Transform>
</RadialGradientBrush>
</Path.Fill>
</Path>
<!-- Layer 3/<Group>/<Path> -->
<Path Fill="#ffffffff" Data="F1 M 23.100586,9.477539 C 24.741699,11.634766 23.116211,15.630859 19.470703,18.404297 C 15.825684,21.178711 11.540039,21.678711 9.899414,19.522461 C 8.258301,17.365234 9.883789,13.369141 13.529297,10.594727 C 17.174316,7.821289 21.459961,7.321289 23.100586,9.477539 Z"/>
</Canvas>
<TextBlock x:Name="dbgwin" FontSize="10" Canvas.Top="10" Canvas.Left="250" Height="500" Width="200" Text="IronPython DLR" />
</Canvas>
</Canvas>
我收到 IOException:找不到资源“app.xaml”。
什么是解决方案?
最佳答案
我让这个工作。我的具体目标是将 ResourceDictionary 加载到 App 类中,这样我就可以从原始 XAML 文件加载自定义外观。就是这样。首先,在 App.xaml 中,添加以下内容:
protected override void OnStartup(StartupEventArgs e) {
base.OnStartup(e);
LoadSkin("Skins/Skin1.xaml");
}
private void LoadSkin(string FilePath) {
XmlReader XmlRead = XmlReader.Create(FilePath);
Application.Current.Resources =
(ResourceDictionary)XamlReader.Load(XmlRead);
XmlRead.Close();
}
创建一个“bin\Debug\Skins”文件夹并添加一个包含以下内容的“Skin1.xaml”:
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
>
<Style x:Key="ButtonAStyle" TargetType="{x:Type Button}">
<Setter Property="Control.Background" Value="Green" />
<Setter Property="Control.Foreground" Value="White" />
</Style>
</ResourceDictionary>
特定于皮肤
在这种特殊情况下,您必须确保在各个窗口中正确使用样式资源。这是一个例子:
<Button
Name="button1"
Style="{DynamicResource ButtonAStyle}"
Click="button1_Click"
>Button</Button>
这里有一个巧妙的技巧可以尝试。在 button1_Click() 中,尝试添加与上面 App.OnStartUp() 中相同的代码,但使用“Skin2.xaml”和“Red”作为按钮的背景色。皮肤会立即改变,无需重新加载应用程序或窗口。
关于wpf - 使用 LoadComponent 加载外部 XAML 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/710329/
我想创建一个包含一堆其他 XAML 文件的主 XAML 文件。这可能吗? 最佳答案 在您的主 Xaml 中,使用 项目控件 balise 和 Xaml 组合器,您必须使用 定义您的项目用户控件 代替
如何在 xaml 中更改 ToggleSwitch 中实际开关的大小?我可以更改 OnContent 和 OffContent 的文本大小,但滑动开关永远不会更改大小。 这些都不会改变开关本身的大小,
我有一个文本 block 列表,其中可能包括里面的 url,比如: 构建失败,请在此处查看更多信息:http://... 构建成功 应用 http://myapp/无法启动,请在此处查看更多信息:ht
我想做的事 我最近一直在探索 XAML 资源字典。它们非常强大,但为了减少(甚至进一步)为适应任何修改而需要进行的更改,我想使用一些基本的算术运算来更改 HeightRequest Entry 的属性
我使用以下代码创建了一个弹出窗口,但我不知道如何将它居中 我试图在运行时自动更改边距,但我不知道该怎么做,但是有人知道如何将弹出窗口居中吗? 它没有标准维度,因为我需要全局化我的程序
哪种类型的命名更适合在 XAML 中使用: xmlns:inventoryControls="clr-namespace:Inventory.Components.Controls;assembly=
我正在尝试格式化我的 string每 3 位有逗号,如果不是整数,则为小数。我检查了大约 20 个示例,这是我最接近的示例: 但我得到一个 The property 'StringFormat' w
在 Windows Phone 8 中,我想将一个图像放在一个圆圈中。是否有类似网格的圆形容器?我知道有椭圆位它不是容器 最佳答案 这是我如何做到的。
有没有办法在 XAML 中检查逻辑非逻辑。我试图绑定(bind)到广泛使用的属性,但是对于这些新的绑定(bind),它的方式是错误的。我不想修改属性,那么有没有办法在 xaml 中反转 bool 结果
在 html 中可以说 width="20%"。这在 XAML 中当然是不允许的。有谁知道为什么会这样或者有没有办法在 XAML 中获得百分比值支持? 最佳答案 网格列定义和行定义允许比例单位(除了固
我可以动态创建 XAML 并将其弹出到我的应用程序中吗?该怎么做呢? 最佳答案 是的,这很简单: XmlReader tXml = XmlReader.Create(myXamlString); UI
简短版: 如果不使用 xamlc 预编译 xaml,应用程序中捆绑了什么以在运行时编译 xaml?它是否取决于 xamarin.forms nugets 之外的应用构建时的当前工具集? 长版: 我们有
我知道如何显示内容页面,但如何根据方向选择正确的布局。我想编写 xaml 文件:一个用于垂直方向,另一个用于水平方向。方向改变时是否可以切换xaml文件 最佳答案 Xamarin.Forms does
我是一名 Android 开发者,我是 Windows Phone 8 的新手 最近我做了一个 android 应用程序..所以我想在 Windows Phone 8 中开发具有相同 View 和相同
在库中编译 XAML 时出现以下错误: Themes\Generic.xaml(35,12): XamlCompiler error WMC0610: XBF generation error cod
我需要在几个不同的 XAML 布局文件中包含一个通用的 XAML。 我不想在其他 XAML 文件中对重复的 XAML 部分进行硬编码。 怎么做包含? 最佳答案 你能把共享代码变成UserControl
我想像这样添加一个符号: 这行不通,所以我尝试用\分隔,但也行不通。有人对我如何做到这一点有任何建议吗? 最佳答案 其实这个问题不是关于XAML的,它只是一个纯XML的问题。 XML中有些字符需要转
我在 Xaml 中定义了这样的列表。 #3599B8 #374649 #FD625E #F2C80F
在向 Microsoft 报告之前,我想在这里问一下。我有一个问题,我无法看到我的 WinUI 3 应用程序的实时可视化树。我什至看不到应用程序内工具栏。我可以在 WPF 和 UWP 应用程序中看到,
我已经定义了一个动画作为一个资源,当通过这样的 EventTrigger 调用时它可以工作: 然后
我是一名优秀的程序员,十分优秀!