![](/img/trans.png)
[英]Cannot style WPF TabControl's TabItem, changes are visible only in VS Designer
[英]Window style not visible in designer
我创建了一个窗口样式(WPF)并将其作为dll添加到我的项目中,当我运行程序时该样式正确显示,但未在设计器中显示。
我已经在Google上搜索过,但是没有一个解决方案在起作用
测试1:
// Window //
Style="{DynamicResource HVE_Window}"
// Window.Resources //
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/GlobalHive.Styles;component/HiveWindow.xaml"/>
</ResourceDictionary.MergedDictionaries>
结果:
Error: 'Window' TargetType doesn not match type of element 'WindowInstance'
-> But it runs and display correctly there
测试2:
// Window //
Style="{DynamicResource MyWindow}"
// Window.Resources //
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/GlobalHive.Styles;component/HiveWindow.xaml"/>
</ResourceDictionary.MergedDictionaries>
<Style x:Key="MyWindow" TargetType="{x:Type Window}" BasedOn="{StaticResource HVE_Window}" />
结果:
No Error:
Still doesn't display in the designer, still shows up if i run the program
测试3:
Both versions but added to application resources
外观如何:
设计师内部的外观:
有时您会发现,尽管在app.xaml中放入了尝试加载内容的任何内容,但在设计时并未加载控件库中的资源。
MS创建了Blend的机制,由于它是Blend的设计者,因此可以在Visual Studio中使用。
这使用称为“ DesignTimeResources.xaml”的“特殊”资源字典
仅在设计时使用。
将一个添加到您的问题exe项目的属性。
与确切的名字。
将所有合并内容放入其中。
例如,这是我的MapEditor项目中的一个项目,该项目使用了UILib的大量资源。 UILib是一个控件库,其中包含各种UI内容。
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:MapEditor">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/UILib;component/Resources/Geometries.xaml"/>
<ResourceDictionary Source="pack://application:,,,/UILib;component/Resources/ControlTemplates.xaml"/>
<ResourceDictionary Source="pack://application:,,,/UILib;component/Resources/FontResources.xaml"/>
<ResourceDictionary Source="pack://application:,,,/UILib;component/Resources/UILibResources.xaml"/>
<ResourceDictionary Source="/Views/Drawing/Terrain/Resources/CityResources.xaml"/>
<ResourceDictionary Source="/Resources/MapEditorResources.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
卸载csproj(在解决方案资源管理器中右键单击),对其进行编辑并找到该资源字典的节点。
更改为:
<Page Include="Properties\DesignTimeResources.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
<ContainsDesignTimeResources>true</ContainsDesignTimeResources>
</Page>
重新加载项目,关闭并重新打开Visual Studio。
您的样式现在应该适用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.