lepoco / lepoco/wpfui

CalendarDatePicker icon disappears when multiple instances are used in XAML

Open
#1,399 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
C#
Stars
9.6k
Forks
1k
PR merge metrics
No merged PRs in 30d

Description

Describe the bug

When placing multiple <ui:CalendarDatePicker /> controls in XAML, the icon of the previously rendered CalendarDatePicker disappears. It seems to be caused by a shared icon resource (e.g. PathGeometry) being reused internally.

This only happens when using more than one CalendarDatePicker on the same view or layout.

To Reproduce
<StackPanel Grid.Row="1" Margin="10">
    <ui:CalendarDatePicker Content="This is first" />
    <ui:CalendarDatePicker Content="2nd" />
    <ui:CalendarDatePicker Content="3rd" />
</StackPanel>
Expected behavior

Each CalendarDatePicker should render its own icon independently without affecting others.

Screenshots

Image

OS version

Windows 10/11

.NET version

.NET 9 or 8

WPF-UI NuGet version

4.0.2

Additional context

As far as I can tell, the issue seems to stem from the Icon property accepting a UIElement, and the current default style provides a single instance of SymbolIcon.
To confirm this, I checked with ReferenceEquals() in code-behind, and both Icon properties were pointing to the same instance.
As a workaround, I replaced them with new instances manually:

if (ReferenceEquals(picker1.Icon, picker2.Icon))
{
    picker1.Icon = new SymbolIcon { Symbol = SymbolRegular.CalendarRtl24 };
    picker2.Icon = new SymbolIcon { Symbol = SymbolRegular.CalendarRtl24 };
}

This approach resolved the issue in my case.
I realize it's not an elegant or scalable solution, and unfortunately, it's the best I could manage at this point.
It would be great if the control could handle icon instancing internally to avoid this type of issue.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by inspecting the CalendarDatePicker default style and its Icon property, then reproduce the issue with multiple controls using the provided XAML. Check whether the style shares one SymbolIcon instance between controls. Done means each CalendarDatePicker retains and renders its own icon independently.

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
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.