For reference, I'm sort of trying to re-create the way Skype displays instant messages. Sender name on the left (left/top aligned) and with the message text on the right. The text on the right should be fixed with, but dynamically expand vertically to show the entire message.
I'm displaying these messages in a ListView. It looks more-or-less like I want it, but I cannot get the TextBox control to expand vertically. It either consumes a single line of 100% width and the text goes off the right edge, or it expands vertically while simultaneously decreasing the width to some value (I can't figure out where that value comes from).
Here's what I currently have. I've tried nested StackPanels as well.
<ListView
x:Name="MessagesListView"
ItemsSource="{Binding Messages}"
TabIndex="1"
Padding="116,46"
Margin="0,0,0,46"
VerticalContentAlignment="Stretch"
SelectionMode="None"
IsItemClickEnabled="false"
IsSwipeEnabled="false">
<ListView.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="200" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<TextBlock
Grid.Column="0"
Text="{Binding ContactDisplayName}"
Margin="0,0,20,0"
TextWrapping="WrapWholeWords" />
<StackPanel Grid.Column="1" Orientation="Vertical">
<TextBox Text="{Binding MessageText}" IsReadOnly="true" />
<TextBlock Text="{Binding TimestampDisplayText}" TextWrapping="Wrap" />
</StackPanel>
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
Does anyone know how to get this to work?
Update 1
Here's a screenshot of what it currently looks like.
Update 2
Okay, I'm getting closer.
First, I realized that I was missing the TextWrap="Wrap" directive on the TextBox control. Unfortunately, setting that resulted in this:
Inspired by Yuliam and Chris's comments, I tried setting specific widths and heights, with varying levels of success. The closest I got to getting what I want is by setting the MinWidth property of the textbox to 500. That yields this:
That's a whole lot closer to what I want. But I still haven't been able to get the TextBox to expand horizontally to fill the grid column. I've tried specifying HorizontalAlignment and HorizontalContentAlignment explicitly, but no change.
It seems the TextBox really only wants to dynamically expand in ONE direction. You either get horizontal or vertical expansion, but not both.
ContactDisplayName
in each item / row to fill theListView
available space proportionally ? a screenshot of your problem would be great.. – Yuliam ChandraGrid's Height
like 100 and check whether it can expand vertically.. – Yuliam Chandra