progressbar not updating binding

Posted by BoteRock on Stack Overflow See other posts from Stack Overflow or by BoteRock
Published on 2013-11-02T21:39:07Z Indexed on 2013/11/02 21:53 UTC
Read the original article Hit count: 157

Filed under:
|

I am trying to make a progress bar that updates when a property value changes I have followed other questions but i don't know what is wrong with it.

This is XAML code:

<Window
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="clr-namespace:WpfApplication1" x:Class="WpfApplication1.MainWindow"
        Title="MainWindow">
    <Grid Margin="0,0,-8,1">
        <ProgressBar Value="{Binding Progreso, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:MainWindow}}}" Margin="105,95,207,350"/>
        <Button Content="Button" Click="Button_Click" Margin="218,232,333,217"/>

    </Grid>
</Window>

it is basically a progress bar with the binding and a button with a listener that increases Progreso by 10 this is the C# code:

public partial class MainWindow : Window
{
    public MainWindow()
    {
        InitializeComponent();
    }

    public event PropertyChangedEventHandler PropertyChanged;

    protected void NotifyPropertyChanged(string sProp)
    {

        if (PropertyChanged != null)
        {
            PropertyChanged(this, new PropertyChangedEventArgs(sProp));
        }
    }

    float progreso = 10;
    public float Progreso
    {
        get
        {
            return progreso;
        }
        set
        {
            progreso = value;
            NotifyPropertyChanged("Progreso");
        }
    }

    private void Button_Click(object sender, RoutedEventArgs e)
    {
        this.Progreso = this.Progreso + 10;
    }

}

I tried to keep it simple but I couldn't get it to work, any help with this would be appreciated.

edit: I've also tried UpdateSourceTrigger=PropertyChanged and that didn't work either

© Stack Overflow or respective owner

Related posts about c#

Related posts about wpf