Border Control in Windows Phone 7, Auto Height & Width not right - xaml

I have a ListBox with this template in it.
<phone:PhoneApplicationPage.Resources>
<DataTemplate x:Key="Template">
<StackPanel Margin="0,10">
<Border BorderBrush="Black" BorderThickness="1" Background="#FFFFC000" Width="460" MinHeight="76">
<StackPanel Margin="4,4,-4,-153">
<TextBlock Text="{Binding }" HorizontalAlignment="Center" VerticalAlignment="Top" Foreground="Black" TextWrapping="Wrap"/>
<TextBlock " Text="{Binding Mode=OneWay}" HorizontalAlignment="Center" VerticalAlignment="Top" Foreground="Black" TextWrapping="Wrap"/>
</StackPanel>
</Border>
</StackPanel>
</DataTemplate>
</phone:PhoneApplicationPage.Resources>
Yet I have to force set a Width and Height on the Border otherwise it makes like Width and Height of "2".
It is like it does not understand I have 2 TextBlock inside it and won't expand to fill both of them.
This leaves me with having to put a fixed height and width in what I don't like as if the text is too big it gets cutoff.

You can toss out your StackPanel's because you don't need them, they're also what's keeping your wrapping from working, you need a panel like a Grid for that. The negative Margin's also isn't something you'd normally see in a DataTemplate for a ListBox so I'd guess you have some other funky layout stuff going on from that sort of practice elsewhere up the tree.
<phone:PhoneApplicationPage.Resources>
<DataTemplate x:Key="Template">
<Grid Margin="0,10">
<Border BorderBrush="Black" BorderThickness="1" Background="#FFFFC000"/>
<TextBlock TextWrapping="Wrap"
HorizontalAlignment="Center" Margin="4,4,-4,-153">
<Run Text="{Binding }"/><LineBreak/>
<Run Text="{Binding Mode=OneWay}"/>
</TextBlock>
</Grid>
</DataTemplate>
</phone:PhoneApplicationPage.Resources>
So unless I'm missing something somewhere this should fix you up as the Grid will handle the sizes of its children for you and consume the space necessary in its parent. However if there's something else in your structure pushing stuff around and won't let it consume that space it should invoke your Wrapping.
Hope this helps :)

Related

Is it possible to create a TextBlock style with border - or do I have to create a UserControl?

At the moment, I keep repeating the XAML below used in titles what I want to improve.
<Border Grid.Row="1" Grid.Column="1" Background="{StaticResource Brush.Black24}" CornerRadius="4">
<TextBlock Margin="8" FontFamily="Segoe UI Semibold" FontSize="14" Foreground="White" VerticalAlignment="Center" Text="BUILT IN MODULES"/>
</Border>
Apparently TextBlocks have no template. I think creating a UserControl is a bit excessive. In addition, I would have to deal with Attached Properties. Any ideas?

UWP XAML Binding to another object is not working

I'm trying to bind TextBlock Width to another object's Width.
It is not working, TextBlock Width stays as the Text length, and not as "BitsListView" Width.
An interesting thing is, when I edit the "Width" of TextBlock while debugging, the binding is working OK.
<StackPanel >
<StackPanel Orientation="Horizontal" >
<TextBlock Text="{x:Bind name}" Width="{Binding ElementName=BitsListView, Path=ActualWidth }"/>
</StackPanel>
<ListBox x:Name="BitsListView" ItemsSource="{x:Bind BitsList, Mode=TwoWay}">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal"/>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
</ListBox>
</StackPanel>
Any ideas?
UWP XAML Binding to another object is not working
The problem is that when set TextBlock root panel Orientation property as Horizontal, the width of content will be fixed. So, if you want to make Binding work, please remove Orientation property like the following.
<StackPanel>
<Border BorderBrush="Red" BorderThickness="2" HorizontalAlignment="Stretch" Margin="0,0,0,0">
<TextBlock Name="TestBlock" Text="Test input some" Width="{Binding ElementName=BitsListView, Path=ActualWidth}"/>
</Border>
</StackPanel>

TextTrimming inside a scrollviewer

Im trying to have a textblock inside a scrollviewer, and if the text exceds the scrollviewer width, have it trimmed.
The text should display the "..." indicating thre is more text, so that the user can scroll to see the rest of the text.
right now i have something like this, but the text trimming inst working.
<ScrollViewer Grid.Row="1" HorizontalScrollMode="Enabled" HorizontalScrollBarVisibility="Hidden" VerticalScrollMode="Disabled" VerticalScrollBarVisibility="Hidden">
<TextBlock Margin="0,5,0,0" Text="{Binding Item.Name}" FontFamily="Segoe UI Semibold" Foreground="White" FontSize="20" FontWeight="SemiBold" VerticalAlignment="Center" TextTrimming="WordEllipsis"/>
</ScrollViewer>

Doesnt show the full article

I have some long article to show in an view. So I made a TextBlock and bound Text with Content property.
Xaml:
<Grid Margin="12,24,12,0"
Background="White">
<TextBlock FontSize="{StaticResource PhoneFontSizeExtraLarge}"
FontFamily="{StaticResource PhoneFontFamilySemiLight}"
Foreground="Black"
Text="{Binding Column.Title}"
TextWrapping="Wrap"
Margin="0,0,0,12"
VerticalAlignment="Top" />
<ScrollViewer Margin="0,62,0,10">
<TextBlock FontSize="{StaticResource PhoneFontSizeMediumLarge}"
Text="{Binding Column.Content}"
TextWrapping="Wrap" />
</ScrollViewer>
</Grid>
The last paragrafs of the article:
The problem is that it doesn’t show the last paragraphs O_o:
What is the problem and how can I fix it?
The reason for this behavior is that any element that must be displayed beyond the area which is larger than 2048x2048 pixels would be clipped by the platform.
Maybe this article can help you : Creating Scrollable TextBlock for WP7.

Windows 8 Metro XAML. How to change background of grid on hover and/or click

I would like to change the background of my grid to white when you hover over or select it. I'd also like to change the color of the text inside at the same time to black. This is specific to one page only, so it would need to be applied with an XKey or something as a guess. The grid starts with a transparent background, also.
I'm really struggling to find the direction for this. Please let me know if you have any ideas or links!
Here's my code:
<GridView.ItemTemplate>
<DataTemplate>
<Grid VerticalAlignment="Top" HorizontalAlignment="Left" Width="335" Height="152">
<StackPanel Orientation="Horizontal" Margin="2,2,2,2" VerticalAlignment="Top" HorizontalAlignment="Left">
<StackPanel Margin="13,0,13,0" Orientation="Vertical" VerticalAlignment="Top" HorizontalAlignment="Left">
<StackPanel Orientation="Horizontal" VerticalAlignment="Bottom">
<TextBlock Style="{StaticResource SmallText}" Text="{Binding Town}" />
<TextBlock Style="{StaticResource SmallText}" Text=", "/>
<TextBlock Style="{StaticResource SmallText}" Text="{Binding State}"/>
<TextBlock Style="{StaticResource SmallText}" Text=", "/>
<TextBlock Style="{StaticResource SmallText}" Text="{Binding Postcode}"/>
</StackPanel>
</StackPanel>
</StackPanel>
</Grid>
</DataTemplate>
</GridView.ItemTemplate>
Thanks for any help.
It seems like you would probably want to modify your GridView's ItemContainerStyle and change its background and visual states to match your requirements. Check my answer to an earlier question related to restyling items here to learn how to extract and modify these styles and templates.