Skip to content

fix(ProgressBar): Replace StaticResource with DynamicResource to reso…#230

Merged
ghost1372 merged 1 commit intoghost1372:developfrom
lyvielle:patch-1
May 5, 2025
Merged

fix(ProgressBar): Replace StaticResource with DynamicResource to reso…#230
ghost1372 merged 1 commit intoghost1372:developfrom
lyvielle:patch-1

Conversation

@lyvielle
Copy link
Contributor

@lyvielle lyvielle commented May 5, 2025

Problem:
When a ProgressBar using the ProgressBarBaseStyleAlt style is instantiated on a different thread, the window crashes with:

System.InvalidOperationException: Cannot use a DependencyObject that belongs to a different thread than its parent Freezable.
The root cause is the StaticResource ProgressBarIndicatorAnimatedFill reference in the PART_GlowRect Rectangle. Since StaticResource is thread-affine, reusing it across threads violates WPF's threading model.

Fix:
Replace StaticResource with DynamicResource for ProgressBarIndicatorAnimatedFill:

<Rectangle x:Name="PART_GlowRect" 
           Fill="{DynamicResource ProgressBarIndicatorAnimatedFill}" 
           HorizontalAlignment="Left" 
           Margin="-100,0,0,0" 
           Width="100"/>

…lve cross-thread exceptions

Fix cross-thread crashes in ProgressBar style by replacing StaticResource with DynamicResource for ProgressBarIndicatorAnimatedFill - StaticResource fails when windows reopen on new threads
@ghost1372 ghost1372 merged commit e9f8377 into ghost1372:develop May 5, 2025
1 check passed
@ghost1372
Copy link
Owner

Thank you @lua-was-taken

@lyvielle lyvielle deleted the patch-1 branch May 5, 2025 12:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants