WPF TextBlock Binding to DependencyProperty

Posted by Bill Campbell on Stack Overflow See other posts from Stack Overflow or by Bill Campbell
Published on 2009-06-03T17:42:08Z Indexed on 2010/04/06 16:53 UTC
Read the original article Hit count: 429

Hi, I have what I believe to be about one of the most simple cases of attempting to bind a view to a dependencyproperty in the view model. It seems that the initial changes are reflected in the view but other changes to the DP do not update the view's TextBlock. I'm probably just missing something simple but I just can't see what it is. Please take a look...

My XAML has a status bar on the bottom of the window. I want to bind to the DP "VRAStatus".

        <StatusBar x:Name="sbar" Grid.Column="0" Grid.Row="2" Grid.ColumnSpan="2" 
               VerticalAlignment="Bottom" Background="LightBlue" Opacity="0.4" DockPanel.Dock="Bottom" >
            <StatusBarItem>
                <TextBlock x:Name="statusBar" Text="{Binding VRAStatus}" />
            </StatusBarItem>
            <StatusBarItem>
                <Separator Style="{StaticResource StatusBarSeparatorStyle}"/>
            </StatusBarItem>
        </StatusBar>

My viewmodel has the DP defined:

    public string VRAStatus
    {
        get { return (string)GetValue(VRAStatusProperty); }
        set { SetValue(VRAStatusProperty, value); }
    }

    // Using a DependencyProperty as the backing store for VRAStatus. 
    public static readonly DependencyProperty VRAStatusProperty =
        DependencyProperty.Register("VRAStatus", typeof(string), typeof(PenskeRouteAssistViewModel),new PropertyMetadata(string.Empty));

Then, in my code I set the DP:

        VRAStatus = "Test Message...";

Is there something obvious here that I am missing? In my constructor for the viewmodel I set the DP like this:

        VRAStatus = "Ready";

I never get the Test Message to display. Please Help.

thanks in advance! Bill

© Stack Overflow or respective owner

Related posts about dependency-properties

Related posts about wpf