【发布时间】:2019-09-19 16:52:11
【问题描述】:
我正在尝试为我的所有页面设置我的字体系列...
在包含页面框架的 MainWindow 中,我有以下内容:
<Window.Style>
<Style TargetType="{x:Type Window}">
<Setter Property="FontFamily" Value="Fonts/Gotham Rounded Light.OTF#Gotham Rounded Light" />
</Style>
</Window.Style>
<Window.Triggers>
在我后面的 MainWindow 代码中有这个:
Style = (Style)FindResource(typeof(Window));
页面字体仍然没有改变......知道我可能做错了什么吗?我不确定主窗口将如何在创建的所有页面上反映其样式
App.xaml 背后的代码
using Engine;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
using System.Windows;
namespace V
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
Window mainWindow = null;
string dllToLoad = null;
App()
{
Startup += App_Startup;
}
void App_Startup(object sender, StartupEventArgs e)
{
try
{
ReadJson();
Window wnd = LoadRunTimeDLL();
wnd.WindowState = WindowState.Minimized;
wnd.Show();
}
catch (Exception ex)
{
System.Diagnostics.Trace.WriteLine(string.Format("Failed to load window from{0} - {1}", "OtherWindow", ex.Message));
throw new Exception(String.Format("Failed to load window from{0} - {1}", "OtherWindow", ex.Message), ex);
}
}
private void ReadJson()
{
using (StreamReader r = new StreamReader("../../Config/Config.json"))
{
string json = r.ReadToEnd();
var jsonData = JsonConvert.DeserializeObject<RootObject>(json);
dllToLoad = jsonData.DllToLoad;
}
}
private Window LoadRunTimeDLL()
{
string assemblyName = string.Format("{0}\\{1}.dll",
new FileInfo(Assembly.GetExecutingAssembly().Location).DirectoryName, dllToLoad);
if (assemblyName != null)
{
Assembly asm = Assembly.LoadFile(assemblyName);
Type[] tlist = asm.GetTypes();
foreach (Type t in tlist)
{
if (t.Name == "MainWindow")
{
mainWindow = Activator.CreateInstance(t) as Window;
break;
}
}
}
return mainWindow;
}
}
}
还有 App.XAML
<Application x:Class="V.App" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:V" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" d1p1:Ignorable="d" xmlns:d1p1="http://schemas.openxmlformats.org/markup-compatibility/2006">
</Application>
【问题讨论】:
-
Edney 我已经读过,但它不起作用。该页面并未将所有元素都设置为该字体。
-
我们可以看看你的 App.xaml
-
已发布,刚刚更新
-
即App.xaml.cs文件。请发布应用程序,xam 文件。它会像