Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用自定义样式创建自定义窗口_C#_Wpf_Resourcedictionary - Fatal编程技术网

C# 使用自定义样式创建自定义窗口

C# 使用自定义样式创建自定义窗口,c#,wpf,resourcedictionary,C#,Wpf,Resourcedictionary,我的目标是创建一个窗口,当我使用它时,我可以看到我的风格。我计划将此窗口作为视图的根。因此,我想使用而不是作为我的根目录。我的visual studio解决方案如下所示: 我计划使用我命名为style.xaml的以下资源字典: <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/20

我的目标是创建一个窗口,当我使用它时,我可以看到我的风格。我计划将此窗口作为视图的根。因此,我想使用
而不是
作为我的根目录。我的visual studio解决方案如下所示:

  • 我计划使用我命名为style.xaml的以下资源字典:

    <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> 
    
      <Style TargetType="{x:Type TextBlock}" >
        <Setter Property="FontFamily" Value="Wingdings 3"/>
      </Style>
    
    </ResourceDictionary>
    
  • 现在我想使用该窗口而不是常规窗口类。然后我创建了一个名为Window1.xaml的新窗口,它看起来像:

    我的测试块

    • 注意我必须如何引用:xmlns:my=“clr namespace:ClassLibrary1.Style;assembly=ClassLibrary1”*
  • 现在为什么我只在运行时看到字体?如何查看我在设计时指定的字体???我还放置了:

    this.FontFamily = new System.Windows.Media.FontFamily("Arial Black");
    
    MyWindow的构造函数中,而不是合并字典

    this.FontFamily = new System.Windows.Media.FontFamily("Arial Black");