【问题标题】:Binding parent container props to content child control in Silverlight在 Silverlight 中将父容器道具绑定到内容子控件
【发布时间】:2011-04-06 19:42:47
【问题描述】:

示例:

<UserControl x:Name="userControl"
    <StackPanel x:Name="container" Margin="0">
        <TextBox Text="{Binding Path=SettingValue, RelativeSource={RelativeSource Mode=Self}}"/>
    </StackPanel>
</UserControl>

UserControl 包含 SettingValue 依赖属性,TextBox 没有, 所以这个例子行不通。

如果我有 AncestorType,我可以做到这一点,就像在 WPF 中一样:

RelativeSource Mode=FindAncestor, AncestorType={x:Type UserControlType}

是否有可能绑定到 UserControl.SettingValue 属性?

【问题讨论】:

    标签: silverlight data-binding


    【解决方案1】:

    您是否尝试过以下操作?使用ElementName 源(语法可能有点不对)。

     <TextBox Text="{Binding Path=SettingValue, ElementName=userControl"/>
    
    【解决方案2】:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-09-06
      • 2013-02-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-01-27
      • 2011-05-11
      • 2011-05-22
      相关资源
      最近更新 更多