C# 如何在silverlight中绑定页面属性?
我有一个silverlight页面,在codebehind中有一个布尔属性 在xaml中,我有一个tabcontrol,在tabitem的一个内容中有一个busyindicatorC# 如何在silverlight中绑定页面属性?,c#,.net,wpf,silverlight,xaml,C#,.net,Wpf,Silverlight,Xaml,我有一个silverlight页面,在codebehind中有一个布尔属性 在xaml中,我有一个tabcontrol,在tabitem的一个内容中有一个busyindicator 我想将busyindicator的isbusy属性绑定到codebehind中的boolean属性,但无论使用哪种绑定语句,我都无法解析它。我有这样的标签 public string Caption { get; set; } void UserControl_Loaded(object sender
我想将busyindicator的isbusy属性绑定到codebehind中的boolean属性,但无论使用哪种绑定语句,我都无法解析它。我有这样的标签
public string Caption { get; set; }
void UserControl_Loaded(object sender, RoutedEventArgs e)
{
Caption = "Label";
}
在XAML中
<Label Content="Label" Height="28" Name="label1" DataContext="{Binding Caption}" />
我相信你也可以用忙指示器做同样的事情。我有这样的标签
public string Caption { get; set; }
void UserControl_Loaded(object sender, RoutedEventArgs e)
{
Caption = "Label";
}
在XAML中
<Label Content="Label" Height="28" Name="label1" DataContext="{Binding Caption}" />
我相信您也可以对忙碌指示器执行相同的操作。在代码隐藏中,您需要确保已设置DataContext。因此,在页面的加载事件中,放置以下内容:
this.DataContext = this;
如果您已经这样做了,那么您需要发布更多详细信息。在codebehind中,您需要确保您已经设置了DataContext。因此,在页面的加载事件中,放置以下内容:
this.DataContext = this;
如果您已经这样做了,那么您需要发布更多详细信息。Slugster确实有一个简洁的解决方案,但我认为您需要的是这个
<Page x:Name="MyPage>
<TabControl>
<TabItem>
<BusyIndicator IsBusy="{Binding ElementName=MyPage, Path=MyBooleanPropertyNameInCodeBehind}" />
</TabItem>
</TabControl>
Slugster确实有一个简洁的解决方案,但我想你要找的是这个
<Page x:Name="MyPage>
<TabControl>
<TabItem>
<BusyIndicator IsBusy="{Binding ElementName=MyPage, Path=MyBooleanPropertyNameInCodeBehind}" />
</TabItem>
</TabControl>
Slugster和AntSlay,这两种解决方案都有效。我发现这同样有效:
<Page DataContext="{Binding RelativeSource={RelativeSource Self}}">
<TabControl>
<TabItem>
<BusyIndicator IsBusy="{Binding MyBooleanPropertyNameInCodeBehind}" />
</TabItem>
</TabControl>
</Page>
Slugster和AntSlay,这两种解决方案都有效。我发现这同样有效:
<Page DataContext="{Binding RelativeSource={RelativeSource Self}}">
<TabControl>
<TabItem>
<BusyIndicator IsBusy="{Binding MyBooleanPropertyNameInCodeBehind}" />
</TabItem>
</TabControl>
</Page>