Skip to content

XAML Binding Failures when ProgressBar is styled with MaterialDesignCircularProgressBar in v5.2.1 (Was working in v5.1.0) #3814

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
shochinhwa opened this issue Mar 13, 2025 · 2 comments · Fixed by #3868
Labels
Milestone

Comments

@shochinhwa
Copy link

Bug explanation

Problem

Encountered multiple binding failures in XAML when ProgressBar is styled with MaterialDesignCircularProgressBar. There was no binding failures previously in v5.1.0 and it appears only after I upgraded it to the latest v5.2.1.

Steps

  1. Create a clean Example solution.
<Application
    x:Class="Example.App"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
    StartupUri="MainWindow.xaml">
    <Application.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <materialDesign:BundledTheme
                    BaseTheme="Light"
                    PrimaryColor="DeepPurple"
                    SecondaryColor="Lime" />
                <ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesign3.Defaults.xaml" />
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Application.Resources>
</Application>
  1. Add a ProgressBar with MaterialDesignCircularProgressBar style.
<Window
    x:Class="Example.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:circularProgressBar="clr-namespace:MaterialDesignThemes.Wpf.Converters.CircularProgressBar;assembly=MaterialDesignThemes.Wpf"
    xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
    Title="MainWindow"
    Width="800"
    Height="450"
    Style="{StaticResource MaterialDesignWindow}"
    mc:Ignorable="d">
    <Grid>
        <ProgressBar
            Width="50"
            Height="50"
            IsIndeterminate="True"
            Style="{StaticResource MaterialDesignCircularProgressBar}"
            Value="0" />
    </Grid>
</Window>
  1. Run (F5) and voila! See below.

Image

Image

Code

  • Example.zip
  • Uncomment <Window.Resources> in MainWindow.xaml for the workaround

Workaround

  • I'm currently overriding the style in Resources by reverting it back to the style in v5.1.0.
  • I believe this bug was introduced when the global converter was converted to instance. StaticResource to x:Static
  • I did some research, seems like a x:Static instance converter doesn't work well with ElementName binding because it has no access to the visual tree? (shrug)
  • Please consider reverting this style to use StaticResource converter until there is a fix

Version

v5.2.1

@shochinhwa shochinhwa added bug evaluation required Items is pending review or evaluation by the team labels Mar 13, 2025
@corvinsz
Copy link
Member

corvinsz commented Mar 13, 2025

As mentioned in this stackoverflow post, adding a x:Name to the PathFigure and ArcSegment somehow solves this problem. I have no idea why.
The changes would be made in the following 2 lines:

<PathFigure StartPoint="{Binding ElementName=PathGrid, Path=ActualWidth, Converter={x:Static circularProgressBarConverters:StartPointConverter.Instance}, Mode=OneWay}">

e.g.:

...
<PathFigure x:Name="innerPathFigure" StartPoint="{Binding ElementName=PathGrid, Path=ActualWidth, Converter={x:Static circularProgressBarConverters:StartPointConverter.Instance}, Mode=OneWay}">
  <ArcSegment x:Name="innerArcSegment" Size="{Binding ElementName=PathGrid, Path=ActualWidth, Converter={x:Static circularProgressBarConverters:ArcSizeConverter.Instance}, Mode=OneWay}" SweepDirection="Clockwise">
...

Because I don't understand the "fix" mentioned above, I am not (yet) going to open a PR. Maybe we can find a different, more viable solution.

Update

While applying an x:Name fixes this particular issue, I don't think this is the correct fix.
The problem that is reported here is a general problem with the static referenced converters which was implemented in #3732.
We probably have this issue all throughout the library (e.g. see #3834)

I noticed it again today: this bug does not break apps itself, but it sure is annoying for the devs to sort out the errors when you are instead hunting for binding errors in your app.

@george7378
Copy link

Also seeing this on the MaterialDesignCircularProgressBar, and on other controls like the Expander and MaterialDesignDataGridCell:

Image

Image

Image

I wonder if there are any plans to address this? Thanks!

@Keboo Keboo added this to the 5.3.0 milestone Jun 13, 2025
@Keboo Keboo removed the evaluation required Items is pending review or evaluation by the team label Jun 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants