我有一组非常简单的样式,我在几个不同的WPF应用程序中使用样式。我将这种风格存储在一个通用项目的Xaml文件中,然后通过合并到Resources
的App.xaml
中添加到每个项目中。样式TargetType在未连接到调试器时导致XamlParseException
<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}”语法怎么样? –
Jay
@Jay:不幸的是,结果相同。 –
您是否将您的自定义控件的样式放入Themes/Generic.xaml中? –