WPF. TextBlock and TextBox aligned properly - wpf

What I have when size of Border container is wide enough:
Name Value NameLonger Value
then size of Border gets smaller and I have something like this:
Name Value NameLonger V
I used WrapPanel and achieved something like this:
Name Value
NameLonger Value
It is better but I would like to achieve something like this:
Name Value
NameLonger Value
Is it possible to achieve such thing?

not sure if i totally understand what you are explaining but based on what i think yiou are describing, would this be what you are looking for?
<Border>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"></ColumnDefinition>
<ColumnDefinition Width="Auto"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
</Grid.RowDefinitions>
<!--Put your textblocks in here-->
</Grid>
</Border>

Use a grid as your container panel. Set the first column width to use as much width as it needs ("auto") and the second column to use the rest ("*").
Place the textblock in the first column, and the textbox in the second.
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"></ColumnDefinition>
<ColumnDefinition Width="*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<textblock .../>
<textbox grid.column="1".../>
</Grid>

Related

WPF - Layouts design

I'm trying to design a layout in a WPF window but I'm having a bit of trouble. enter image description here
That is the layout Im after. Ive tried grids, stack panels, etc.. but I cannot get the right docking or they overlap.
Any ideas ?? Thanks!
First make 2 rows , then 2nd row with 3 cols
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="20*"/>
<RowDefinition Height="80*"/>
</Grid.RowDefinitions>
<Grid Grid.Row="1">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="20*"/>
<ColumnDefinition Width="60*"/>
<ColumnDefinition Width="20*"/>
</Grid.ColumnDefinitions>
</Grid>
</Grid>

Bind MaxWidth to calculated Auto value

I have a datatemplate containing this section. The second column is used for a GridSplitter.
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="auto" MaxWidth="100"/>
<ColumnDefinition Width="auto"/>
</Grid.ColumnDefinitions>
<Grid>
What I am trying to do is to bind the MaxWidth of the first column to the width of its content instead of a hardcoded width value.
The idea is that the user can make the column narrower than its content but not wider.
Is this possible with simple binding?
OneTime Binding to Actual Width of the content UserControl did the trick!
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="auto" MaxWidth="{Binding ActualWidth, ElementName=ColumnContent, Mode=OneTime}" />
<ColumnDefinition Width="auto" />
</Grid.ColumnDefinitions>
<Grid>

WPF AutoCompleteBox Width based on Content

I have an System.Windows.Controls.AutoCompleteBox with a fixed width.
The width should dynamically grow based on the content.
How can I achieve this.
Thanks for your help
You can achieve it by placing the AutoCompleteBox in a Grid.Column with Width="Auto". Here's an example:
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" MinWidth="30" />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<toolkit:AutoCompleteBox />
</Grid>

Resize window parts in runtime

I want to have main window split in three parts like the one on the picture. there's supposed to be a line (red one) or left border of the rectangle number 2, that, when it's dragged with mouse, it resizes both rectangle 1 and 2. it's like the behaviour of playlist in windows media player. any ideas on how to obtain this? Also, it would be great if someone proposes a solution to how this playlist make collapsed if the red line is dragged to the right.
Define a <Grid> with columns and rows like so:
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="300"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="600"/>
<ColumnDefinition Width="20"/>
<ColumnDefinition Width="300"/>
</Grid.ColumnDefinitions>
...
and then the gridsplitter (still inside the grid):
<GridSplitter Grid.Row="0" Grid.Column="1" ResizeDirection="Columns" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"/>
Note that the gridsplitter will need it's own column.
It is a GridSplitter, here is how to use one:
<GridSplitter Grid.Row="1"
Height="5"
Width="Auto"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Background="Gray"
ResizeDirection="Rows" />
You need to assign a Row or Column to it from your Grid, and specify its ResizeDirection. This one is horizontal, but you get the idea for a vertical one.
HTH,
Bab.

Expand a control to fill grid column

I'm having a problem getting a panelbar to expand it's width to match the Grid column it occupies. The offending code is the second appearance of a panelbar with an item header named "Operators". I can set the width explicitly to fill the column, but that would only show correctly for my specific resolution and is not the solution I'm looking for. I would just like it to stretch on it's own. Code snippet below.
<telerik:RadTabControl telerik:StyleManager.Theme="Windows7" Grid.Column="2">
<telerik:RadTabItem Header="Add/Edit">
<Grid ShowGridLines="True">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"></ColumnDefinition>
<ColumnDefinition Width="Auto"></ColumnDefinition>
</Grid.ColumnDefinitions>
<TextBlock FontSize="20" Grid.Row="0">Organization Name Here:</TextBlock>
<my1:QueryBuilder Height="Auto" Width="Auto" Grid.Row="1"></my1:QueryBuilder>
<telerik:RadPanelBar ExpandMode="Single" Grid.Column="1" Grid.Row="1" Width="Auto"
VerticalContentAlignment="Stretch" HorizontalContentAlignment="Stretch"
HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<telerik:RadPanelBarItem Header="Operators"></telerik:RadPanelBarItem>
</telerik:RadPanelBar>
</Grid>
</telerik:RadTabItem>
</telerik:RadTabControl>
You Second ColumnDefinition should have Width of "*" not "Auto" as you have currently.

Resources