Silverlight: Why doesn't this binding expression work?

Posted by Rosarch on Stack Overflow See other posts from Stack Overflow or by Rosarch
Published on 2010-12-29T18:48:32Z Indexed on 2010/12/29 18:53 UTC
Read the original article Hit count: 151

Filed under:
|
|

I'm having difficulty with a binding expression in Silverlight 3 for the Windows Phone 7.

    <Grid x:Name="LayoutRoot" Background="Transparent">

        <controls:Pivot ItemsSource="{Binding SectionViewModels}">
            <!-- ... -->
            <controls:Pivot.ItemTemplate>
                <DataTemplate>
                    <Grid>

                        <!-- this is the troublesome binding -->
                        <TextBlock Style="{StaticResource disabledText}" Visibility="{Binding ElementName=LayoutRoot, Path=DataContext.NoStoryContent}">
                            Do you have a network connection?
                        </TextBlock>
<!-- ... -->

The style, in app.xaml:

        <Style x:Key="disabledText" TargetType="TextBlock">
            <Setter Property="Foreground" Value="{StaticResource PhoneDisabledBrush}" />
            <Setter Property="TextWrapping" Value="Wrap" />
            <Setter Property="FontSize" Value="{StaticResource PhoneFontSizeLarge}" />
        </Style>

Code behind:

    public Visibility NoStoryContent
    {
        get
        {
            // trivial return value for debugging
            // no breakpoint here is hit
            return Visibility.Collapsed;
        }
    }

    public Sections()
    {
        InitializeComponent();
        LayoutRoot.DataContext = this;
    }

What am I doing wrong here? I suspect I have a mistake in the binding expression, but I'm not sure where.

© Stack Overflow or respective owner

Related posts about c#

Related posts about Silverlight