spiegelp / MaterialDesignExtensions

Material Design Extensions is based on Material Design in XAML Toolkit to provide additional controls and features for WPF apps
https://spiegelp.github.io/MaterialDesignExtensions/
MIT License
762 stars 122 forks source link

Binding Issue of StepButtonBar #151

Open allenlooplee opened 3 years ago

allenlooplee commented 3 years ago

Hello,

Currently I defined a Stepper with StepButtonBar in XAML in a WPF app targeting .NET Framework 4.8 in Visual Studio 2019. I noticed the below error in Output window when running the app.

System.Windows.Data Error: 4 : Cannot find source for binding with reference 'RelativeSource FindAncestor, AncestorType='MaterialDesignExtensions.Controls.IStepper', AncestorLevel='1''. BindingExpression:Path=Layout; DataItem=null; target element is 'StepButtonBar' (Name=''); target property is 'Mode' (type 'StepperLayout')

The same issue also showed in the XAML Binding Failures when running the app.

Inside the StepButtonBar of the last step, I tried to bind its CancelCommand and ContinueCommand to CancelCommand and FinishCommand of the bound view model respectively. But the code didn't execute when I clicked the buttons in the StepButtonBar. I have two normal buttons on the same step which also bound to the same commands respectively and the code executed as expected.

I have attached the code as below for your reference. Do I miss something important to make it work or does this hit some bug somehow?

WpfApp1.zip

Thanks/Allen

Imadlekal commented 2 years ago

Any fixes or workarounds for this? Apparently, they're still not working.

allenlooplee commented 2 years ago

Any fixes or workarounds for this? Apparently, they're still not working.

I don't think there're any official fixes or workarounds for the time being. I used the following helper method in my view models whenever I wanted the Stepper to move to next step:

private void NextStep()
{
    MaterialDesignExtensions.Commands.Internal.StepperCommands.ContinueCommand.Execute(this, null);
}
balAdamT commented 1 year ago

Those commands are tempting to bind to, it's what I tried to first too.

But looking at the documentation, they instead seem to recommend binding to the ContinueNavigationCommand of the Stepper control itself.

Not sure if we have the exact same use case but this worked for me:

<mde:Stepper 
    x:Name="Stepper"
    IsLinear="False" 
    ContentAnimationsEnabled="False" 
    Layout="Horizontal" 
    Steps="{Binding Path=SubSteps, Mode=OneWay}"
    ContinueNavigationCommand="{Binding ElementName=Stepper, Path=ActiveStep.Content.SaveCommand}"
    />