【问题标题】:How to bind to page property in silverlight?如何绑定到 Silverlight 中的页面属性?
【发布时间】:2011-07-05 02:16:27
【问题描述】:

我在代码隐藏中有一个带有布尔属性的 silverlight 页面。

在 xaml 中,我有一个 tabcontrol,其中一个 tabitem 的内容是一个忙指示符。

我想将busyindicator的isbusy属性绑定到codebehind中的boolean属性,但是无论使用什么绑定语句都无法解决。

【问题讨论】:

    标签: c# .net wpf silverlight xaml


    【解决方案1】:

    Slugster 确实有一个巧妙的解决方案,但我认为您正在寻找的是这个

    <Page x:Name="MyPage>
    <TabControl>
        <TabItem>
           <BusyIndicator IsBusy="{Binding ElementName=MyPage, Path=MyBooleanPropertyNameInCodeBehind}" /> 
        </TabItem>
    </TabControl>
    

    【讨论】:

      【解决方案2】:

      Slugster 和 AntSlay,您的两个解决方案都有效。我发现这也有效:

      <Page DataContext="{Binding RelativeSource={RelativeSource Self}}">
          <TabControl>
              <TabItem>
                 <BusyIndicator IsBusy="{Binding MyBooleanPropertyNameInCodeBehind}" /> 
              </TabItem>
          </TabControl>
      </Page>
      

      【讨论】:

        【解决方案3】:

        在代码隐藏中,您需要确保已设置 DataContext。因此,在页面的 Load 事件中,输入以下内容:

        this.DataContext = this;
        

        如果您已经这样做了,那么您需要发布更多详细信息。

        【讨论】:

          【解决方案4】:

          我有这样的标签

             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}" />
          

          我相信你可以用忙碌指示器做同样的事情。

          【讨论】:

            猜你喜欢
            • 2011-02-03
            • 2011-07-15
            • 1970-01-01
            • 2012-01-31
            • 2011-02-15
            • 2011-01-26
            • 1970-01-01
            • 2010-12-11
            • 1970-01-01
            相关资源
            最近更新 更多