Skip to main content
Home Forums Silverlight Programming Silverlight Controls and Silverlight Toolkit Silverlight 2.0 RC0 the ContentControl is broken!
8 replies. Latest Post by hhristov on October 2, 2009.
(0)
coughlinj
Member
334 points
114 Posts
09-26-2008 12:20 AM |
That may be an over reaction but the change they made to make it extend Framework element has totally messed up my layouts.
Controls that once stretched to fill the complete screen are now sized only to the size of their content. No more fluid layouts for me:)
Please let me know if there is a work around or if this is indeed a bug. I'm sure its related to the breaking change "ContentPresenter now derives from FrameworkElement instead of Control".
I've simplified this to the following app...
Page.xaml
----------------------
MyControl.xaml
---------------------
<UserControl x:Class="ContentTest.MyControl" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> <Grid x:Name="LayoutRoot"> <Rectangle Fill="Black" Stretch="Fill" /> <TextBlock Text="Hello World" Foreground="Wheat" /> </Grid></UserControl>
Output:
Beta 2 - The Black Rectangle fills the entire browser window.
RC0 - The Block Rectangle covers only the Text "Hello World". The Red background of the page.xaml control fills the remainder of the window.
hhristov
20 points
5 Posts
09-26-2008 4:52 AM |
This is the default behavior for ContentControl because the Style for ContentControl have these setters:
So you have 2 options:
Your XAML should look like this (in the 2nd case):
<
</Grid>
Hope this helps
Regards,
Hristo
09-26-2008 10:34 AM |
Perfect. That's it. I had tried changing the HorizontalAlignment but not the "ContentAlignment". Thanks so much!
rfcdejong
2 points
1 Posts
07-09-2009 4:14 AM |
If i had just found this post earlier. It took me in total 3 hours to find out why my sandribbon wouldn't fit the browser size. Using CAG i have a ContentControl defined as Region and i was looking in the wrong corner. The default.aspx hosting page, the silverlight plugin control, the page itself.I did look at the ContentControl but overlooked HorizontalContentAlignment, i tried HorizontalAlignment.Anyway, what is the difference between those?
07-09-2009 1:24 PM |
HorizontalAlignment is for the ContentControl. What this means is that if are measured with lets say 100, 100 and you have HorizontalAlignment=Stretch then the ContentControl will return DesiredSize 100 (for Width). If you set HorizontalContentAlignment to Stretch then the content (or to be precise the container for this content which is ContentPresenter if the content is not UIElement or the UIElement) will take all the available width. But if you set HorizontalContentAlignment to Center then the ContentControl will take all available Width and the content will be Centered in this width.
I hope I've explained it well.
Mark Stega
11 points
16 Posts
10-01-2009 1:16 PM |
I actually have another thread (http://forums.silverlight.net/forums/p/132041/295723.aspx#295723) about this same issue. I have the content control as a Prism region. I associate a view & its view-model with the content control (it is an owner control with a grid) and I can not get it to size to the full reqion even when I use the 'content' alignment as suggested above.
10-01-2009 2:05 PM |
Hello Mark,
by default HorizontalAlignment and VerticalAlignment are Stretch for ContentControl so you shound not set the to stretch.
You should only set HorizontalContentAlignment and VerticalContentAlignment to stretch for ContentControl if you want its content stretched.
Let me know if this works for you.
10-02-2009 11:57 AM |
I have HorizontalAlignment & VerticalAllignment as Center and the HorizontalContentAlignment & VerticalContentAlignment as Stretch.
The content is now horizontally centered, but vertically it is at the top and the content did not stretch so it appears not to have helped.
10-02-2009 3:49 PM |
Like I said you should not set VerticalAlignment to Stretch because it is the default value. You should set it only if you need to have other value (like Top, Center or Bottom).
If you want your content to be stretched verticaly you should set both VerticalAignment and VerticalContentAignment to stretch. Or just VerticalContentAignment to stretch (and don't set VerticalAignment because by default it is Stretch).