HandyOrg / HandyOrg/HandyControl
CheckComboBox 无法同时设置 DisplayMemberPath 和 ItemTemplate
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 7.2k
- Forks
- 1.2k
- PR merge metrics
- No merged PRs in 30d
Description
Describe the bug
CheckComboBox 无法同时设置 DisplayMemberPath 和 ItemTemplate,设计时错误,运行时也错误,但是如果这个 CheckComboBox 作为 DataGridTemplateColumn 的 CellTemplate,那么又没问题。
Timestamp: 2026/3/15 星期日 上午 11:40:59
OSVersion: Microsoft Windows NT 10.0.26200.0
ClrVersion: 10.0.3
ThreadName: N/A(2)
----------------------------------------
Handler: DispatcherUnhandledException
----------------------------------------
Type: System.Windows.Markup.XamlParseException
Source: PresentationFramework
Message: “设置属性“System.Windows.Controls.ItemsControl.ItemTemplate”时引发了异常。”,行号为“246”,行位置为“43”。
TargetSite: Void RewrapException(System.Exception, System.Xaml.IXamlLineInfo, System.Uri)
StackTrace:
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 System.Reflection.MethodBaseInvoker.InvokeWithFewArgs(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, RuntimeResolverContext context)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSiteMain(ServiceCallSite callSite, TArgument argument)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitDisposeCache(ServiceCallSite transientCallSite, RuntimeResolverContext context)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(ServiceCallSite callSite, TArgument argument)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.Resolve(ServiceCallSite callSite, ServiceProviderEngineScope scope)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.DynamicServiceProviderEngine.<>c__DisplayClass2_0.<RealizeService>b__0(ServiceProviderEngineScope scope)
at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService(ServiceIdentifier serviceIdentifier, ServiceProviderEngineScope serviceProviderEngineScope)
at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService(Type serviceType)
at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider provider, Type serviceType)
at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService[T](IServiceProvider provider)
at CommunityToolkit.Mvvm.Input.RelayCommand.Execute(Object parameter)
at System.Windows.Controls.MenuItem.InvokeClickAfterRender(Object arg)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
HResult: -2146233087
HelpLink: null
--- Inner Exception (Level 1) ---
Type: System.InvalidOperationException
Source: PresentationFramework
Message: 无法同时设置 DisplayMemberPath 和 ItemTemplate。
TargetSite: Void CheckTemplateSource()
StackTrace:
at System.Windows.Controls.ItemsControl.CheckTemplateSource()
at System.Windows.Controls.ItemsControl.OnItemTemplateChanged(DataTemplate oldItemTemplate, DataTemplate newItemTemplate)
at System.Windows.FrameworkElement.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
at System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args)
at System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType)
at System.Windows.DependencyObject.SetValueCommon(DependencyProperty dp, Object value, PropertyMetadata metadata, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType, Boolean isInternal)
at MS.Internal.Xaml.Runtime.ClrObjectRuntime.SetValue(Object inst, XamlMember property, Object value)
HResult: -2146233079
HelpLink: null
InnerException: null
Steps to reproduce the bug
- 添加 CheckComboBox 并同时设置 DisplayMemberPath 和 ItemTemplate
- 运行程序 -> 异常
- 将 CheckBomboBox 移动到 DataGridTemplateColumn 的 CellTemplate 再次运行 -> 正常
Expected behavior
No response
Screenshots
No response
NuGet package version
HandyControls (Custom version) 3.6.0
IDE
Visual Studio 2026
Framework type
.Net 10.0
Windows version
Windows 11
Additional context
No response
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the issue with a CheckComboBox that sets both DisplayMemberPath and ItemTemplate, then compare it with the same control inside a DataGridTemplateColumn CellTemplate. Trace the control's template-property handling and verify that the standalone case no longer throws while preserving the working templated-column behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- desktop
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 38/100