Silverlight: Why doesn't this binding expression work?
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 (for Visibility) -->
<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:
开发者_Go百科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.
Update: I don't see any error messages in the debug output.
Update 2: When I say 'doesn't work', I mean 'the control is always visible even though I'm trying to make it be collapsed, and the property that its Visibility is binding to is never accessed.'
try just {Binding NoStoryContent}
You should implement iNotifyPropertyChanged in your class
精彩评论