[英]Silverlight: Why doesn't this binding expression work?
I'm having difficulty with a binding expression in Silverlight 3 for the Windows Phone 7. 我在使用Windows Phone 7的Silverlight 3中的绑定表达式时遇到困难。
<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 : 样式,在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. 我怀疑绑定表达式中有错误,但是我不确定在哪里。
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.' 更新2 :当我说“不起作用”时,我的意思是“即使我试图使其折叠,该控件始终是可见的,并且其可见性所绑定的属性从未访问过。”
试试{Binding NoStoryContent}
您应该在您的课程中实现iNotifyPropertyChanged
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.