Answered by:
How to set TextBox width Based on Border width dynamically in c#

Question
-
Hi,
I am working on filled view. here I have a requirement as follows.
I have a TextBox which is inside a Border. here I am setting textbox width based on Border Width as follows in xaml.
<Border x:Name="TextBoxBorder" BorderThickness="0" Margin="0,0,5,0"> <TextBox x:Name="InputDialBox" Style="{StaticResource AlcatelTextBoxStyle}" Width="{Binding ElementName=TextBoxBorder, Path=ActualWidth}" VerticalAlignment="Top" Height="Auto" Margin="0,0,0,0"/> </Border>
I want to set width as above (Width="{Binding ElementName=TextBoxBorder, Path=ActualWidth}") of textbox "InputDialBox" through c# code.
can anyone suggest me best way to achieve the same.
Thanks in Advance.
- Edited by Siddenki Wednesday, July 24, 2013 6:15 AM
Wednesday, July 24, 2013 6:14 AM
Answers
-
You can simply set the horizontal alignment property of the textbox to stretch. It will take all the horizontal space of the border.
The best things in life are free, but the most valuable ones are costly...use opportunities well for there are others like you who deserves them, but don't have them...
- Proposed as answer by SoHassan Wednesday, July 24, 2013 9:07 PM
- Marked as answer by Matt SmallMicrosoft employee, Moderator Monday, July 29, 2013 7:00 PM
Wednesday, July 24, 2013 4:59 PM -
I looked at this code and it seems to work fine. If you don't put a width at all on the textbox, it should consume all of the available space (excluding margins, etc). What is the real problem you're seeing with this?
Matt Small - Microsoft Escalation Engineer - Forum Moderator
If my reply answers your question, please mark this post as answered.
NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.- Marked as answer by Matt SmallMicrosoft employee, Moderator Monday, July 29, 2013 7:00 PM
Wednesday, July 24, 2013 2:50 PMModerator -
Hi Siddenki,
You can write below code in your xaml.cs file as
this.InputDialBox.Width = this.TextBoxBorder.ActualWidth
Thanks
Ajay
- Marked as answer by Matt SmallMicrosoft employee, Moderator Monday, July 29, 2013 7:00 PM
Wednesday, July 24, 2013 4:42 PM
All replies
-
I looked at this code and it seems to work fine. If you don't put a width at all on the textbox, it should consume all of the available space (excluding margins, etc). What is the real problem you're seeing with this?
Matt Small - Microsoft Escalation Engineer - Forum Moderator
If my reply answers your question, please mark this post as answered.
NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.- Marked as answer by Matt SmallMicrosoft employee, Moderator Monday, July 29, 2013 7:00 PM
Wednesday, July 24, 2013 2:50 PMModerator -
Hi Siddenki,
You can write below code in your xaml.cs file as
this.InputDialBox.Width = this.TextBoxBorder.ActualWidth
Thanks
Ajay
- Marked as answer by Matt SmallMicrosoft employee, Moderator Monday, July 29, 2013 7:00 PM
Wednesday, July 24, 2013 4:42 PM -
You can simply set the horizontal alignment property of the textbox to stretch. It will take all the horizontal space of the border.
The best things in life are free, but the most valuable ones are costly...use opportunities well for there are others like you who deserves them, but don't have them...
- Proposed as answer by SoHassan Wednesday, July 24, 2013 9:07 PM
- Marked as answer by Matt SmallMicrosoft employee, Moderator Monday, July 29, 2013 7:00 PM
Wednesday, July 24, 2013 4:59 PM