开发者

Binding parent container props to content child control in Silverlight

开发者 https://www.devze.com 2023-01-14 22:32 出处:网络
Example: <UserControl x:Name=\"userControl\" <StackPanel x:Name=\"container\" Margin=\"0\"> <TextBox Text=\"{Binding Path=SettingValue, RelativeSource={RelativeSourc开发者_如何学编程e Mod

Example:

<UserControl x:Name="userControl"
    <StackPanel x:Name="container" Margin="0">
        <TextBox Text="{Binding Path=SettingValue, RelativeSource={RelativeSourc开发者_如何学编程e Mode=Self}}"/>
    </StackPanel>
</UserControl>

UserControl contains SettingValue dependency property, TextBox doesn't, so this example won't work.

I could've done this if I had AncestorType, like in WPF:

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

Is there any possibility to bind to UserControl.SettingValue property?


Did you try the following? Use the ElementName source (the syntax might be a bit off).

 <TextBox Text="{Binding Path=SettingValue, ElementName=userControl"/>


The answer I've found here:

Binding Silverlight UserControl custom properties to its' elements

0

精彩评论

暂无评论...
验证码 换一张
取 消