How do I get line break in textBlock working - c#

I somehow can't seem to get a line break in my TextBlock.
TextWrapping="Wrap" doesn't work. Also anything else such as TextTrimming doesn't affect my TextBlock at all. I assume an other control is blocking? Talking about the "txtErrorLabel"
<Window x:Class="BLVKServiceDashboard.Pages.ErrorWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="ErrorWindow" Height="555" Width="420" Icon="/BLVKServiceDashboard;component/error.ico" ResizeMode="NoResize" WindowStartupLocation="Manual" ShowInTaskbar="False" Background="#FFEEEEEE" WindowStyle="None">
<Grid Margin="0,0,4,-3" RenderTransformOrigin="0.588,0.554">
<Label Content="Fehlermeldungen" HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top" FontFamily="Segoe UI Semibold" FontSize="25"/>
<ListBox x:Name="lstErrorItems" ScrollViewer.VerticalScrollBarVisibility="Auto" BorderThickness="0" Background="{x:Null}" Margin="0,58" ScrollViewer.HorizontalScrollBarVisibility="Disabled">
<ListBox.ItemTemplate>
<DataTemplate>
<Grid Width="500" Height="38" Margin="0,0,0,0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="380"/>
<ColumnDefinition Width="120"/>
</Grid.ColumnDefinitions>
<ScrollViewer Grid.ColumnSpan="2">
<StackPanel Orientation="Horizontal">
<TextBlock Foreground="Black" Text="Fehler: " HorizontalAlignment="Left" Height="Auto" Width="Auto" VerticalAlignment="Top" Margin="5,10,0,2" FontSize="14" FontFamily="Segoe UI" ScrollViewer.VerticalScrollBarVisibility="Disabled"/>
<TextBlock x:Name="txtErrorLabel" Foreground="Black" Text="{Binding}" HorizontalAlignment="Left" Height="Auto" VerticalAlignment="Top" Margin="5,10,0,2" FontSize="14" FontFamily="Segoe UI"/>
</StackPanel>
</ScrollViewer>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<Button x:Name="btnDelete" Content="Meldungen löschen" Margin="147,514,147,0" VerticalAlignment="Top" Width="122" Click="btnDelete_Click" HorizontalContentAlignment="Center" RenderTransformOrigin="0.467,0.909"/>
</Grid>

Your textblock is in stackPanel which gives no boundary to your textBlock.
change parent to something which provides boundary to your textblock or set limits to stack panel itself.
TextWrapping will come into effect only when the textblock exceeds width of parent control. But stackPanel never imposes any boundary to its childs and hence all space is available.
a possible solution can be --
<Grid Width="500" Height="Auto" Margin="0,0,0,0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="380"/>
<ColumnDefinition Width="120"/>
</Grid.ColumnDefinitions>
<ScrollViewer Grid.ColumnSpan="2">
<Grid >
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<TextBlock Foreground="Black" Text="Fehler: " HorizontalAlignment="Left" Height="Auto" Width="Auto" VerticalAlignment="Top" Margin="5,10,0,2" FontSize="14" FontFamily="Segoe UI" ScrollViewer.VerticalScrollBarVisibility="Disabled"/>
<TextBlock Grid.Column="1" x:Name="txtErrorLabel"
Foreground="Black"
TextWrapping="Wrap"
Text="123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789"
HorizontalAlignment="Left"
VerticalAlignment="Top"
Margin="5,10,0,2"
FontSize="14" FontFamily="Segoe UI"/>
</Grid>
</ScrollViewer>
</Grid>

Related

Align TextBlock in Button / StackPanel correctly

I try to align the TextBlocks to the left.
The button should take the rest of the area (Up to the picture).
How can I do this?
This is a UWP / C# App.
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition/>
</Grid.RowDefinitions>
<Grid VerticalAlignment="Center" HorizontalAlignment="Left">
<Button Background="Transparent" HorizontalAlignment="Stretch">
<StackPanel HorizontalAlignment="Left">
<TextBlock x:Name="TextBlock1" TextWrapping="Wrap" Text="Name1"/>
<TextBlock x:Name="TextBlock2" TextWrapping="Wrap" Text="Name2" />
</StackPanel>
</Button>
</Grid>
<StackPanel Grid.Column="1" Grid.Row="0" HorizontalAlignment="Right">
<Button Height="50" Width="50" Background="Transparent" Click="Button_Click">
<Image x:Name="ImageFavorit" Source="/Assets/Stern/VGrau64.png"/>
</Button>
</StackPanel>
</Grid>
Firstly you should replace your ColumnDefinitions to this:
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
And secondly remove HorizontalAlignment="Left" from your Grid then you can achieve to what you want:
<Grid VerticalAlignment="Center">
<Button Background="Transparent" HorizontalAlignment="Stretch">
...
Also it seems that you need to set VerticalAlignment="Center" of your StackPanel too:
<StackPanel Grid.Column="1" Grid.Row="0"
HorizontalAlignment="Right" VerticalAlignment="Center">
Update: Based on your comment that you want the text on the left side Set the HorizontalContentAlignment="Left" of the Button:
<Button Background="Transparent" HorizontalAlignment="Stretch"
HorizontalContentAlignment="Left">

Trouble with WPF ScrollViewer resize

I have an issue with a ScrollViewer in WPF.
When a Window is sized down to the point where the ScrollViewer should start taking over, the window doesn't resize the containing grid and bottom of the scroll bar just goes out of view.
I have tried binding the height of it to the height of the containing grid, but with no luck.
Here is my xaml:
<Grid x:Name="MainGrid" Width="Auto" Height ="Auto" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<StackPanel Height="134" Width="Auto" VerticalAlignment="Top" Background="Blue" HorizontalAlignment="Stretch">
<Label x:Name="ProjectNumberLabel" Content="ProjectNumber" HorizontalAlignment="Left" Height="45.5" VerticalAlignment="Top" Width="350" FontSize="32" Margin="10,0,0,0" Foreground="White"/>
<Label x:Name="ProjectNameLabel" Content="ProjectName" HorizontalAlignment="Stretch" Height="42" VerticalAlignment="Top" FontSize="24" Margin="10,0,0,0" Foreground="White" Width="auto"/>
<Label x:Name="SetLabel" Content="Set Id" HorizontalAlignment="Stretch" Width="Auto" Height="42" Margin="10,0,10,0" FontSize="24" VerticalAlignment="Top" Foreground="White" />
</StackPanel>
<ScrollViewer HorizontalAlignment="Stretch" Margin="0,140,0,0" Width="Auto" CanContentScroll="True" Height="{Binding ElementName=MainGrid, Path=ActualHeight }">
<StackPanel Name="ContainingPanel" VerticalAlignment="Top" HorizontalAlignment="Stretch" Width="Auto" Height="Auto">
<StackPanel HorizontalAlignment="Stretch" Width="Auto" Height="300"/>
<StackPanel HorizontalAlignment="Stretch" Height="38" VerticalAlignment="Bottom">
<CheckBox x:Name="ComplexDataCheckBox" Content="Show All Data" Click="ComplexDataCheckBox_Click" RenderTransformOrigin="1.751,0.547" Margin="0,4,0,0" Height="16" HorizontalAlignment="Right" Width="105" VerticalAlignment="Bottom">
<CheckBox.LayoutTransform>
<ScaleTransform ScaleX="2" ScaleY="2" />
</CheckBox.LayoutTransform>
</CheckBox>
</StackPanel>
<StackPanel HorizontalAlignment="Stretch">
<syncfusion:SfDataGrid HorizontalAlignment="Stretch" Width="Auto" VerticalAlignment="Stretch" x:Name="SpecimenGrid" AutoGenerateColumns="True" RowStyleSelector="{StaticResource styleselector}"/>
</StackPanel>
</StackPanel>
</ScrollViewer>
</Grid>
if ScrollViewer has a Height equal to Grid height and not zero-vertical margin, it goes out Grid bounds.
it is better to put StackPanel and ScrollViewer in two separate Grid Rows:
<Grid x:Name="MainGrid">
<Grid.RowDefinitions>
<RowDefinition Height="140"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<StackPanel Grid.Row="0">
<!--Content-->
</StackPanel>
<ScrollViewer Grid.Row="1"
HorizontalAlignment="Stretch"
Margin="0"
CanContentScroll="True" >
<!--Content-->
</ScrollViewer>
</Grid>

GridView Data overlays with Header after vertical scrolling in Microsoft Store App

I have a GridView that looks as follows:
<Page
x:Name="pageRoot"
x:Class="View.ServiceModule"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:View"
xmlns:common="using:View.Common"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Page.Resources>
<CollectionViewSource
x:Name="groupedItemsViewSource"
Source="{Binding ServiceTasksFiltered}"
IsSourceGrouped="true"
ItemsPath="ServiceTasksFiltered">
</CollectionViewSource>
</Page.Resources>
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Grid.ChildrenTransitions>
<TransitionCollection>
<EntranceThemeTransition/>
</TransitionCollection>
</Grid.ChildrenTransitions>
<Grid.RowDefinitions>
<RowDefinition Height="140"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<GridView
Visibility="Collapsed"
x:Name="serviceTasksFilteredGridView"
TabIndex="1"
Grid.RowSpan="2"
Padding="116,136,116,46"
ItemsSource="{Binding ServiceTasksFiltered, Mode=TwoWay}"
SelectionMode="None"
IsSwipeEnabled="false"
IsItemClickEnabled="true"
ScrollViewer.VerticalScrollMode="Auto"
ScrollViewer.VerticalScrollBarVisibility="Auto"
VerticalAlignment="Top">
<GridView.ItemContainerStyle>
<Style TargetType="GridViewItem">
<Setter Property="HorizontalAlignment" Value="Stretch"/>
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
</Style>
</GridView.ItemContainerStyle>
<GridView.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel HorizontalAlignment="Stretch"/>
</ItemsPanelTemplate>
</GridView.ItemsPanel>
<GridView.Header>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="100"></ColumnDefinition>
<ColumnDefinition Width="200"></ColumnDefinition>
<ColumnDefinition Width="500"></ColumnDefinition>
<ColumnDefinition Width="300"></ColumnDefinition>
<ColumnDefinition Width="300"></ColumnDefinition>
</Grid.ColumnDefinitions>
<TextBlock Text="Debitornr." TextWrapping="Wrap" FontSize="24" FontWeight="Bold"/>
<TextBlock Grid.Column="1" Text="Name" TextWrapping="Wrap" FontSize="24" FontWeight="Bold"/>
<TextBlock Grid.Column="2" Text="Belegnr." TextWrapping="Wrap" FontSize="24" FontWeight="Bold"/>
<TextBlock Grid.Column="3" Text="Reaktionsdatum" TextWrapping="Wrap" FontSize="24" FontWeight="Bold"/>
<TextBlock Grid.Column="4" Text="Priorität" TextWrapping="Wrap" FontSize="24" FontWeight="Bold"/>
</Grid>
</GridView.Header>
<GridView.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="100"></ColumnDefinition>
<ColumnDefinition Width="200"></ColumnDefinition>
<ColumnDefinition Width="500"></ColumnDefinition>
<ColumnDefinition Width="300"></ColumnDefinition>
<ColumnDefinition Width="300"></ColumnDefinition>
</Grid.ColumnDefinitions>
<TextBlock Text="{Binding CustomerNo}" TextWrapping="Wrap" FontSize="20"/>
<TextBlock Grid.Column="1" Text="{Binding CustomerName}" TextWrapping="Wrap" FontSize="20"/>
<TextBlock Grid.Column="2" Text="{Binding DocumentNo}" TextWrapping="Wrap" FontSize="20"/>
<TextBlock Grid.Column="3" Text="{Binding ResponseDateDisplay}" TextWrapping="Wrap" FontSize="20"/>
<TextBlock Grid.Column="4" Text="{Binding PriorityDisplay}" TextWrapping="Wrap" FontSize="20"/>
</Grid>
</DataTemplate>
</GridView.ItemTemplate>
</GridView>
<!-- Back button and page title -->
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="120"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Button x:Name="backButton" Margin="39,59,39,0"
Click="BackButton"
Style="{StaticResource NavigationBackButtonNormalStyle}"
VerticalAlignment="Top"
AutomationProperties.Name="Back"
AutomationProperties.AutomationId="BackButton"
AutomationProperties.ItemType="Navigation Button"/>
<TextBlock x:Name="pageTitle" Text="Serviceaufgaben" Style="{StaticResource HeaderTextBlockStyle}" Grid.Column="1"
IsHitTestVisible="false" TextWrapping="NoWrap" VerticalAlignment="Bottom" Margin="0,0,30,40"/>
</Grid>
</Grid>
When I try to scroll down to display the bottom rows, the top rows are being moved higher instead of disappearing. Please see the following picture for a better descirption:
GridView with wrong scrolling settings
As you can see the GridView is scrolled down and the rows are behind the header of the page. I need them to disappear.
Any help would be greatly appreciated.

How make ScrollViewer work properly - windows phone 8

I have added a ScrollViewer object on my application page and I have added many control objects on the ScrollViewer object but the end-user using the app can not view all the elements because the Scroll does not scroll low enough, and the page keeps returning to it's original position before the user has the opportunity to enter any information.
My XAML code is here:
<phone:PhoneApplicationPage
x:Class="ChronosMobile.PhoneApp.OrçamentoPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
SupportedOrientations="Portrait" Orientation="Portrait"
mc:Ignorable="d"
shell:SystemTray.IsVisible="True">
<!--LayoutRoot is the root grid where all page content is placed-->
<Grid x:Name="LayoutRoot" Background="Transparent" Margin="0,0,0,-153">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid x:Name="LayoutRoot1" Background="#FF4F8899" Margin="0,0,0,59">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<!--TitlePanel contains the name of the application and page title-->
<!--ContentPanel - place additional content here-->
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<ScrollViewer Margin="-10,0,10,169">
<StackPanel Height="916">
<TextBox x:Name="txtNomeCliente" Height="Auto" TextWrapping="Wrap"
Text="" Background="White" BorderBrush="White" IsReadOnly="True"/>
<Button x:Name="BotaoCatalogo" Content="Catálogo"
Width="Auto" Height="80" VerticalAlignment="Top" Background="#FF3FAACA" BorderBrush="#FF3FAACA" Click="BotaoCatalogo_Click"/>
<Button x:Name="BotaoItens" Content="Itens"
Width="Auto" Height="80" VerticalAlignment="Top" Background="#FF3FAACA" BorderBrush="#FF3FAACA" Click="BotaoItens_Click"/>
<Grid Background="#FF0F3B48" Margin="12,0,12,0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<StackPanel Grid.Column="0"
VerticalAlignment="Center"
Orientation="Horizontal"
Margin="5">
<TextBlock Text="Qtde. de Itens:"
FontSize="{StaticResource PhoneFontSizeMedium}"/>
<TextBlock x:Name="lblQuantidadeProdutos" Text="0" Margin="10,0,0,0" FontSize="{StaticResource PhoneFontSizeMedium}" Width="43"/>
</StackPanel>
<StackPanel Grid.Column="1"
VerticalAlignment="Center"
HorizontalAlignment="Right"
Orientation="Horizontal"
Margin="2">
<TextBlock x:Name="lblValorTotal" FontSize="{StaticResource PhoneFontSizeMedium}"/>
</StackPanel>
</Grid>
<Button x:Name="BotaoPagamentos" Content="Adicionar Pagamento"
Width="Auto" Height="80" VerticalAlignment="Top" Background="#FF3FAACA" BorderBrush="#FF3FAACA" Click="BotaoPagamentos_Click"/>
<ListBox x:Name="ListaPagamentos" ItemsSource="{Binding ListaPagamentos}"/>
<ListBox x:Name="ListaEntrega" ItemsSource="{Binding ListaEntrega}"/>
<Grid Background="#FF0F3B48" Margin="12,0,12,0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<StackPanel Grid.Column="0"
VerticalAlignment="Center"
Margin="5">
<TextBlock
FontSize="16" FontWeight="Bold">
<Run FontWeight="Normal" Text="Forma de pagamento: A vista"/>
</TextBlock>
<TextBlock
FontSize="16">
<Run Text="Parcela(s):"/>
<Run Text=" "/>
<Run Text="1"/>
</TextBlock>
<TextBlock
FontSize="16">
<Run Text="Vencimento"/>
<Run Text=":"/>
<Run Text=" "/>
<Run Text="25/05/2013"/>
</TextBlock>
</StackPanel>
<StackPanel Grid.Column="1"
VerticalAlignment="Center"
HorizontalAlignment="Right"
Margin="2">
<TextBlock
FontSize="{StaticResource PhoneFontSizeMedium}" Margin="0">
<Run Text=" "/>
<Run Text="Valor"/>
</TextBlock>
<TextBlock Text="R$ 399,00"
FontSize="{StaticResource PhoneFontSizeMedium}"/>
</StackPanel>
</Grid>
<Button x:Name="cmdEntrega" Content="Entrega" Width="Auto" Height="80" VerticalAlignment="Top" Background="#FF3FAACA" BorderBrush="#FF3FAACA" Click="BotaoEntrega_Click"/>
<Grid Background="#FF0F3B48" Margin="12,0,12,0" Height="50">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="5*"/>
<ColumnDefinition Width="4*"/>
</Grid.ColumnDefinitions>
<StackPanel Grid.Column="0"
VerticalAlignment="Center"
Orientation="Horizontal"
Margin="5,12,81,0" Height="38" Grid.ColumnSpan="2">
<TextBlock x:Name="lblTransportadora"
FontSize="{StaticResource PhoneFontSizeMedium}" Width="149">
<Run FontSize="20" Text="Transportadora"/>
<Run FontSize="20" Text=":"/>
</TextBlock>
</StackPanel>
</Grid>
<Grid Height="13" Width="437"/>
<Grid Background="#FF0F3B48" Margin="12,0,12,0" Height="135">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="5*"/>
<ColumnDefinition Width="4*"/>
</Grid.ColumnDefinitions>
<StackPanel Grid.Column="0"
VerticalAlignment="Center"
Orientation="Horizontal"
Margin="5,12,81,0" Height="38" Grid.ColumnSpan="2">
<TextBlock x:Name="lblTransportadora1"
FontSize="{StaticResource PhoneFontSizeMedium}" Width="58" Margin="0,-2,0,12">
<Run FontSize="20" Text="Rua:"/>
</TextBlock>
</StackPanel>
<TextBlock FontSize="{StaticResource PhoneFontSizeMedium}" Margin="5,11,128,85">
<Run FontSize="20" Text="Descrição:"/>
</TextBlock>
<TextBlock FontSize="{StaticResource PhoneFontSizeMedium}" Margin="5,96,165,10">
<Run FontSize="20" Text="Cidade:"/>
</TextBlock>
<TextBlock x:Name="lblDescricao" Grid.ColumnSpan="2" HorizontalAlignment="Left" Height="26" Margin="113,16,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="315"/>
<TextBlock x:Name="lblRua" Grid.ColumnSpan="2" HorizontalAlignment="Left" Height="26" Margin="113,57,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="317"/>
<TextBlock x:Name="lblCidade" Grid.ColumnSpan="2" HorizontalAlignment="Left" Height="26" Margin="113,99,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="319"/>
</Grid>
<Grid Height="20" Width="437"/>
<TextBlock Text="Informações Adicionais:" Margin="15,10,0,0"/>
<TextBox x:Name="TxtInfoAdicional" Height="Auto" TextWrapping="Wrap"
Text="{Binding InfoAdicional, Mode=TwoWay}" Background="White" BorderBrush="White"/>
<Button x:Name="BotaoFinalizar" Content="Salvar Orçamento"
Width="238" Height="80" VerticalAlignment="Top"
HorizontalAlignment="Right" BorderBrush="#FF3FAACA" Background="#FF3FAACA"/>
</StackPanel>
</ScrollViewer>
</Grid>
</Grid>
<!--TitlePanel contains the name of the application and page title-->
<!--ContentPanel - place additional content here-->
</Grid>
I had the same issue. but at last i solved it, i just used the Height property to do this. Please do the following steps
First create a ScrollViewer
Indide the ScrollViewer create a container(eg: Grid/StackPanel/Border etc...) and put every controlls inside it.
Set fixed Height for ScrollViewer and the Container (Note: Height of container should be greater than ScrollViewer's Height)
See the below Code
<ScrollViewer Height="500">
<Grid Name="Container" Height="700">
<TextBox/>
<TextBox/>
<TextBox/>
</Grid>
</ScrollViewer>
Now you can scroll the container Grid Even the KeyBoard shown or even focus on a TextBox.
You have to set the height of your ScrollViewer. It should be smaller than the StackPanel to achieve the scroll effect you desire. It should also be smaller than the screen size if you wish to see it's entire contents.

3 column grid for xaml is not taking up expected space

I have the following xaml:
<DataTemplate x:Key="ActivityStreamItemTemplate">
<StackPanel VerticalAlignment="Top" Margin="5,0,0,0">
<Button Command="{Binding Path=DataContext.LoadSpacesCommand, ElementName=OrganisationList}" CommandParameter="{Binding}" Padding="-5,0,-5,-5" Margin="-7,-12,-7,-7" Height="auto" BorderThickness="0" HorizontalAlignment="Left" VerticalAlignment="Stretch" HorizontalContentAlignment="Left" UseLayoutRounding="True" FontSize="0.01">
<Grid Height="auto">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="67" />
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="67" />
</Grid.ColumnDefinitions>
<StackPanel Height="auto" Grid.Column="0" Background="Transparent">
<Border Background="Transparent" BorderThickness="0" Width="62" Height="62" HorizontalAlignment="Left" Margin="0,0,0,5">
<Image Source="{Binding created_by.image.link}" Width="62" Height="62"></Image>
</Border>
</StackPanel>
<StackPanel Height="auto" Grid.Column="1">
<TextBlock Text="{Binding type}" HorizontalAlignment="Left" FontSize="30" VerticalAlignment="Center" Margin="0,0,0,5" Foreground="White" />
<TextBlock Text="{Binding ttitle}" HorizontalAlignment="Left" FontSize="15" VerticalAlignment="Center" Margin="0,0,0,5" Foreground="White" TextWrapping="Wrap" MaxWidth="Infinity" />
<TextBlock Text="{Binding created_by.name}" HorizontalAlignment="Left" FontSize="11" VerticalAlignment="Center" Margin="0,0,0,5" Foreground="White" />
</StackPanel>
<StackPanel Height="auto" Grid.Column="2">
<TextBlock Text="{Binding comment_count}"></TextBlock>
</StackPanel>
</Grid>
</Button>
</StackPanel>
</DataTemplate>
As you can see I would like to have the first column of my grid set to 67.. perfect, and working fine...
The next column needs to fill as much as it can of the screen minus the extra columns width after it.
How do I go about doing this?
Kind of linked to this: How to TextWrap a TextBlock within a width Auto Column? but I couldn't get the * thing to work... I'm not sure it really does what I need it to do
It's because you've got:
MaxWidth="Infinity"
on your TextBlock and
<ColumnDefinition Width="Auto"/>
on your column.
This means that the XAML thinks it can grow that column as much as it likes to fit the text in.
If you want the text to wrap you'll have to provide a limit to either the width of the column, the width of the grid or the width of the stack panel.
If you want the middle column to take the remaining space then just specify it's width with a *:
<ColumnDefinition Width="*"/>

Categories