Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/311.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在silverlight中绑定页面属性?_C#_.net_Wpf_Silverlight_Xaml - Fatal编程技术网

C# 如何在silverlight中绑定页面属性?

C# 如何在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

我有一个silverlight页面,在codebehind中有一个布尔属性

在xaml中,我有一个tabcontrol,在tabitem的一个内容中有一个busyindicator


我想将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>