我正在尝试为所有页面设置字体系列...
在包含页面框架的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>
答案 0 :(得分:0)
Window
中的Pages
样式不适用于Frame
。尝试在Page
中定义隐式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">
<Style TargetType="{x:Type Page}">
<Setter Property="TextElement.FontFamily" Value="Times New Roman" />
</Style>
</Application>