【发布时间】:2020-10-09 18:15:34
【问题描述】:
我在 app.xaml 文件中定义了以下资源,效果很好:
<Application.Resources>
<Style TargetType="Button" x:Key="homeButtom">
<Setter Property="Margin" Value="5" />
<Setter Property="Padding" Value="4" />
<Setter Property="Width" Value="110" />
<Setter Property="Background" Value="CadetBlue" />
<Setter Property="Foreground" Value="White" />
<Setter Property="FontSize" Value="14" />
</Style>
</Application.Resources>
然后,我将实体框架添加到解决方案中,并且按照建议,O 从标头中删除了“StartupUri="MainWindow.xaml”,并将调用插入到后面的代码中:
protected override async void OnStartup(StartupEventArgs e)
{
await host.StartAsync();
var mainWindow = host.Services.GetRequiredService<MainWindow>();
mainWindow.Show();
base.OnStartup(e);
}
除非在需要的页面上设置资源,否则资源将无法使用。
只是补充一下,我想这就是原因。事实是我的资源只能在 app.xaml 中使用...
【问题讨论】:
标签: c# wpf xaml code-behind app.xaml