user677607
user677607

Reputation:

C# - Silverlight - How to i bind the width of an element to an other element such that its OneWay Binding?

i have two TextBoxes with x:Name="TextBoxName" and x:Name="TextBoxPhone" i want to be able to bind the width of TextBoxName to TextBoxPhone such that if TextBoxPhone Width changes i want the width of TextBoxName to change too how do i do it?

Upvotes: 2

Views: 4951

Answers (3)

Anwer Ali
Anwer Ali

Reputation: 25

<TextBox Name="TextBoxName" Width="{Binding ElementName=TextBoxPhone, Path=Width, Mode=OneWay}" />

Upvotes: 0

Alex Aza
Alex Aza

Reputation: 78447

In Silverlight 3:

For the TextBox called TextBoxName set Width="{Binding Width, ElementName=TextBoxPhone}"

Good example here http://www.silverlightshow.net/tips/XAML-Element-Binding.aspx

In Silverlight 2:

You would need to do some more work. Example here: http://www.scottlogic.co.uk/blog/colin/2009/02/elementname-binding-in-silverlight-via-attached-behaviours/

Upvotes: 2

schummbo
schummbo

Reputation: 900

Is this what you're looking for?

<TextBox Height="23" HorizontalAlignment="Left" Margin="190,81,0,0" Name="TextBoxName" VerticalAlignment="Top" Width="{Binding ElementName=TextBoxPhone, Path=Width, Mode=OneWay}" />
<TextBox Height="23" HorizontalAlignment="Left" Margin="194,192,0,0" Name="TextBoxPhone" VerticalAlignment="Top" Width="120" />

Upvotes: 0

Related Questions