dotnet / dotnet/wpf

Setting System.Windows.Media.Pen.DashStyle exhibits unreliable behavior

Open
#6,355 3 comments 1 reaction 1 assignee Claimed by @dipeshmsft View on GitHub
Investigate
Dominant language
C#
Stars
7.7k
Forks
1.3k
Avg merge
1d 11h
Merged PRs (30d)
61

Description

* .NET Core Version: 6.0
* Windows version: Windows 10 build 19043.1586
* Does the bug reproduce also in WPF for .NET Framework 4.8?: Yes
* Is this bug related specifically to tooling in Visual Studio (e.g. XAML Designer, Code editing, etc...)? No
* Security issues and bugs should be reported privately, learn more via our [responsible disclosure guidelines](https://github.com/dotnet/wpf/blob/main/README.md#reporting-security-issues-and-security-bugs).



**Problem description:**

Setting `System.Windows.Media.Pen.DashStyle` to a value changes the UI once and not again.

The code sample includes the following code:

```
switch (Counter)
{
case 0:
LineElement.Pen.DashStyle = new DashStyle(new double[] { 4, 6 }, 0);
Counter++;
break;
case 1:
LineElement.Pen.DashStyle = DashStyles.Solid;
Counter++;
break;
case 2:
LineElement.Pen.DashStyle = new DashStyle(new double[] { 4, 6 }, 0);
Counter++;
break;
case 3:
LineElement.Pen.DashStyle = DashStyles.Solid;
Counter++;
break;

default:
throw new ArgumentOutOfRangeException();
}

```
In the above code extracted from my gist, the GUI changes at case 0 correctly and draws a dashed line. Then it fails to update at every other case.

The code copied into a .Net 4.8 WPF app exhibits the same behavior.


**Actual behavior:**

The GUI changes exactly once when the `Pen.DashStyle` dependency property updates. Then it stops updating.

**Expected behavior:**

I expected that setting `Pen.DashStyle` more than once to new values would behave like a dependency property (since it is).

**Minimal repro:**

Create new WPF .Net6 app, call it `WpfApp1`.
Replace all of the code in MainWindow.xaml and MainWindow.xaml.cs with the code in the following gist files:
[https://gist.github.com/NWoodsman/eccbc3c3164bc0691c6841d2836e6684](url)
Run the app and click the button repeatedly.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.