Question

Progressbar and Caliburn Micro

Hello All,

This is my first project using Caliburn so I could be missing something.

I have the below xaml and viewmodel. The view contains a progressbar that is filled to 100% and it reports changes to the method ProgressBar. The method is fired as expected but its Value parameter is always 0.0 I dove into the source code and the dependency property is correctly passed on and contains the % (Eg 22.45546) but for some reason I don't onderstand the parameter isn't bounded and stays 0.0

Any help is greatly appreciated because getting to know Caliburn better is my number 1 priority.

XAML

<ProgressBar Width="100" Height="20" x:Name="ProgressBar">
  <ProgressBar.Triggers>
    <EventTrigger
        RoutedEvent="ProgressBar.Loaded">
      <BeginStoryboard>
        <Storyboard>
          <DoubleAnimation
              Storyboard.TargetName="ProgressBar"
              Storyboard.TargetProperty="Value"
              From="0"
              To="100"
              Duration="0:0:5" />
        </Storyboard>
      </BeginStoryboard>
    </EventTrigger>
  </ProgressBar.Triggers>
</ProgressBar>

C#

public void ProgressBar(double Value)
{
      // Value is always 0.0 ??
}
Était-ce utile?

La solution

What happens is 0.0 is the default value for Double.
You ask for a double but Caliburn does not know what to put in it, so it returns the default.

From the documentation, you should look at this syntax:

<ProgressBar
            Width="100"
            Height="20"
            x:Name="ProgressBar">
            <i:Interaction.Triggers>
                <i:EventTrigger EventName="ProgressChanged">
                    <cal:ActionMessage MethodName="ProgressBar"> 
                            <cal:Parameter Value="{Binding ElementName=ProgressBar, Path=Value}" />
                    </cal:ActionMessage>
                </i:EventTrigger>
            </i:Interaction.Triggers>
            <ProgressBar.Triggers>
                <EventTrigger RoutedEvent="ProgressBar.Loaded">
                    <BeginStoryboard>
                        <Storyboard>
                            <DoubleAnimation Storyboard.TargetName="ProgressBar"
                                             Storyboard.TargetProperty="Value"
                                             From="0"
                                             To="100"
                                             Duration="0:0:5" />
                        </Storyboard>
                    </BeginStoryboard>
                </EventTrigger>
            </ProgressBar.Triggers>
        </ProgressBar>

Where i: is System.Windows.Interactivity

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top