我有一组非常简单的样式,用于几个不同的WPF应用程序。我在一个公共项目中将这个样式存储在Xaml文件中,然后通过合并到每个项目的App.xaml
中的Resources
中添加。
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:dxe="http://schemas.devexpress.com/winfx/2008/xaml/editors"
xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity">
<Style TargetType="dxe:ComboBoxEdit">
<Setter Property="AutoComplete" Value="True" />
<Setter Property="IncrementalFiltering" Value="True" />
<Setter Property="ImmediatePopup" Value="True" />
<Setter Property="IsTextEditable" Value="True" />
<Setter Property="ClearSelectionOnBackspace" Value="True" />
</Style>
<Style TargetType="dxe:ComboBoxEditSettings">
<Setter Property="AutoComplete" Value="True" />
<Setter Property="IncrementalFiltering" Value="True" />
<Setter Property="ImmediatePopup" Value="True" />
<Setter Property="IsTextEditable" Value="True" />
</Style>
</ResourceDictionary>
很不幸,这其中某些原因导致XamlParseException
在处理TargetType
属性时出现问题,但只有在未附加调试器时才会发生。如果我在调试器中启动应用程序,一切都正常。如果我选择“以无调试方式启动”,在加载App.xaml
时就会出现此问题:
System.Windows.Markup.XamlParseException: 'Failed to create a 'TargetType' from the text 'dxe:ComboBoxEdit'.' Line number '5' and line position '12'. ---> System.Xaml.XamlParseException: Type reference cannot find type named '{http://schemas.devexpress.com/winfx/2008/xaml/editors}ComboBoxEdit'.
at MS.Internal.Xaml.Context.ObjectWriterContext.ServiceProvider_Resolve(String qName)
at MS.Internal.Xaml.ServiceProviderContext.System.Windows.Markup.IXamlTypeResolver.Resolve(String qName)
at System.Xaml.Replacements.TypeTypeConverter.ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, Object value)
at MS.Internal.Xaml.Runtime.ClrObjectRuntime.CreateObjectWithTypeConverter(ServiceProviderContext serviceContext, XamlValueConverter`1 ts, Object value)
at MS.Internal.Xaml.Runtime.ClrObjectRuntime.CreateFromValue(ServiceProviderContext serviceContext, XamlValueConverter`1 ts, Object value, XamlMember property)
at System.Xaml.XamlObjectWriter.Logic_CreateFromValue(ObjectWriterContext ctx, XamlValueConverter`1 typeConverter, Object value, XamlMember property, String targetName, IAddLineInfo lineInfo)
--- End of inner exception stack trace ---
at System.Windows.Markup.XamlReader.RewrapException(Exception e, IXamlLineInfo lineInfo, Uri baseUri)
at System.Windows.Markup.WpfXamlLoader.Load(XamlReader xamlReader, IXamlObjectWriterFactory writerFactory, Boolean skipJournaledProperties, Object rootObject, XamlObjectWriterSettings settings, Uri baseUri)
at System.Windows.Markup.WpfXamlLoader.LoadBaml(XamlReader xamlReader, Boolean skipJournaledProperties, Object rootObject, XamlAccessLevel accessLevel, Uri baseUri)
at System.Windows.Markup.XamlReader.LoadBaml(Stream stream, ParserContext parserContext, Object parent, Boolean closeStream)
at System.Windows.Application.LoadComponent(Object component, Uri resourceLocator)
at Shell.App.InitializeComponent() in c:\DevProjects\CoreApplication\Shell\App.xaml:line 1
at Shell.App.Main() in C:\DevProjects\CoreApplication\Shell\obj\x86\Debug\App.g.cs:line 0
如果我注释掉两个Style
节点,那么一切都正常了。有什么想法吗?
TargetType="{x:Type <type>}"
语法怎么样? - Jay