WPF Layout: Textbox growing inside Tabcontrol

Both of these questions say that to bind a stretching textbox to container width/height and not grow with user input, you should user a placeholder border and bind to its actual height/width.

This only sort of works though. It does stop the textbox from growing with user input, but the textbox will only resize to grow, it will never resize to shrink. If you use RenderSize it will grow and shrink, but it will grow with user input again. Also, adding an additional element to bind width/height to seems a bit hacky. Is there a better solution?

This seems like it should be the default behavior of stretching textboxes.

EDIT: Here is the XAML (including Aaron's suggestion below)

<TabControl HorizontalAlignment="Stretch" Margin="5,15,5,5" Name="tabControl2" VerticalAlignment="Stretch" MinHeight="80"> <TabItem Header="Description" Name="tabItem2" FontSize="14" IsEnabled="True"> <Grid> <Border Name="b_desc"/> <TextBox HorizontalAlignment="Stretch" Margin="0" Name="textBox5" VerticalAlignment="Stretch" FontSize="12" TextWrapping="Wrap" AutoWordSelection="True" VerticalScrollBarVisibility="Auto" AcceptsReturn="True" Width="{Binding ElementName=b_desc, Path=ActualWidth}" Height="{Binding ElementName=b_desc, Path=ActualHeight}" MaxWidth="{Binding ElementName=b_desc, Path=Width}" MaxHeight="{Binding ElementName=b_desc, Path=Height}" /> </Grid> </TabItem> </TabControl>

EDIT2: I am not sure if it makes a difference, but these elements are the content of a TabControl bound to a collection of ViewModels. See This Article for an example of the pattern.

-------------Problems Reply------------

Bind the MaxWidth property of the TextBox to the Width property of the container.

<TextBox Width="Auto" MaxWidth="{Binding ElementName=myTabControl, Path=Width}"/>

Category:c# Views:2 Time:2011-08-10
Tags: wpf layout

Related post

  • WPF: Allow TextBox to be resized but not to grow on user input 2009-03-03

    I have a TextBox defined inside a window like so: <Window x:Class="NS.MainWindow" ... SizeToContent="WidthAndHeight"> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="100" /> <ColumnDefinition MinWidth="200" />

  • Styling a WPF layout grid background (of each cell, row, column) 2009-02-19

    I would like to know if there is any way to style a WPF layout grid's cells, rows and columns. I've been trying to find any information and the few mentions I've found have not been that informative. I would like to style the grid to look like the on

  • How do I implement WPF layout if sizes of peer elements are not independent? 2009-06-15

    Imagine I have two WPF FrameworkElements that need to be laid out. One element contains text, and the other shows line numbers for the text. The widths of these two elements are not independent. For example, if the text element gets narrower, then mo

  • Creating custom WPF layout panel - ignored children not disappearing 2010-05-03

    Good afternoon. I'm creating a custom WPF layout control that needs to omit children from the measure/arrange process if they won't fit in the available area. I'm testing with Blend. I have tried overriding GetVisualChild(n) and VisualChildCount to t

  • WPF layout for complex card game 2010-07-21

    As my first WPF project, I am attempting to build an application to play a card game similar to Magic the Gathering. It is not clear to me how to lay out the main play area. You can see some examples that are similar to what I am attempting by lookin

  • WPF: AutoComplete TextBox, -again 2010-02-26

    This other SO question asks about an autocomplete textbox in WPF. Several people have built these, and one of the answers given there suggests this codeproject article. But I've not found any WPF Autocomplete Textbox that compares with the WinForms a

  • TextBlock Wrapping in WPF Layout 2010-04-19

    I'm trying to figure out how to do something similar to the twitter silverlight app that Scott Guthrie demoed recently in WPF: http://weblogs.asp.net/scottgu/archive/2010/03/18/building-a-windows-phone-7-twitter-application-using-silverlight.aspx Unf

  • wpf layout-system problem 2010-07-25

    I'm not too familiar with wpf layout-system. so i'm ready to start and understanding that. at the first of road i have a problem with wpf. so according to below markup, i have 4 button which when we run project everything is true. <Window ... Wind

  • Getting textbox value inside a Detailsview control 2011-03-13

    I have a DetailsView control with a template field as follows: <asp:TemplateField SortExpression="Title"> <ItemTemplate> <asp:TextBox ID="txtMessageTitle" Text='<%# Bind("Title") %>' runat="server"> </asp:TextBox> <as

  • wpf layout managment library 2011-05-10

    Hi I am looking for a wpf layout management library or for an example project paid or open source... I want my user could select layout of the window (one column, two column, mixed column and row...) and then could add gadgets (from my gadget catalog

  • Absolutely centered content inside a WPF layout panel 2009-02-23

    I need to find a way of absolutely centering the content of a LayoutPanel in WPF. I have two textblock elements which must render at the vertical and horizontal center of the panel without relying on absolute heights and widths. This is something i c

  • WPF: TextBox resizes inside ScrollViewer 2010-08-16

    I have a TextBox that stretches to the width of the window: <Window ...> <TextBox VerticalAlignment="Top" /> </Window> However, the textbox should have a minimum width, and I want scroll bars to be shown, if the textbox cannot be di

  • Lazy load data bound list inside TabControl WPF 2011-01-24

    I have a TabControl with three tabs, each containing a DataGrid bound to a list of data. The model behind the view is setup with lazy loaded properties. <TabControl> <TabItem> <DataGrid ItemsSource="{Binding FirstList}" > <DataGr

  • Help with my WPF Layout 2010-08-22

    I have a WPF Line of business application. Most of it is hosted in user controls in tabs. I'm having an issue finding out how to layout this so it would fit any resolution (with scrolling if necessary). Here's the issue described in code because i re

  • Adjusting WPF Layout Controls 2009-07-30

    In a WPF UI Application, I have 4 controls and 3 radio buttons( say write, read and load). I have aligned them Properly too. 4 controls are : 1. Tabcontrol with listview in it 2. Stackpanel with checkboxes 3. Stackpanel(orientation - Horizantal) with

  • wpf / silverlight textbox filter design 2009-10-17

    I have a list that the user can filter in several ways. two of which lend themselves to combo boxes and two that need to accept user input. For example, one textbox allows the user to type in any part of a list item's description, and the dialog will

  • How to place a long Grid in a WPF Layout Container? 2009-11-04

    When I place a Datagrid in a WPF Grid Layout container, the datagrid lengthens the Grid Layout. I want it to occupy only the space available on screen. --------------Solutions------------- Make sure your Grid.ColumnDefinition or Grid.RowDefinition's

  • WPF Layout of user control as a run 2009-11-16

    In WPF, I want to create a Window that looks like the following: On the screen are four user control, #1, 2, 3, 4. As you can see, user control 2 should not be rendered as a box, but inlined. If this were a WPF flow document: 1, 3, 4 would be a parag

  • WPF Layout question- How to scroll and auto-size content? 2010-06-21

    All, I am coming from a primarily ASP.NET background, but have experience with Windows forms as well. I am trying to learn how to layout my WPF app. I have the following code: <Grid> <Grid.RowDefinitions> <RowDefinition Height="40" /

Copyright (C) dskims.com, All Rights Reserved.

processed in 0.170 (s). 11 q(s)