Overlay element over ContentControl's ContentPresenter - xaml

I am trying to get this seemingly simple scenario to work.
I have a ContentControl MyControl, and I would like one of it's elements to overflow on top of the ContentPresenter while remaining an element of a border.
<Page
x:Class="Playground.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Playground"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:controls="using:Playground"
mc:Ignorable="d"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Page.Resources>
<Style TargetType="local:MyControl" >
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="local:MyControl">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="100"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Border Grid.Row="0" BorderBrush="GreenYellow" BorderThickness="1">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="2*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Rectangle Grid.Column="0" Width="50" Height="50" Fill="Silver" HorizontalAlignment="Center"/>
<Rectangle x:Name="Overflow" Grid.Column="1" Width="100" Height="200" Fill="Gold" HorizontalAlignment="Center"/>
<Rectangle Grid.Column="2" Width="50" Height="50" Fill="Silver" HorizontalAlignment="Center"/>
</Grid>
</Border>
<ContentPresenter Grid.Row="1"/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Page.Resources>
<controls:MyControl Grid.Row="0" BorderBrush="Gold" BorderThickness="1">
<Ellipse Fill="Silver"/>
</controls:MyControl>
</Page>
I have tried playing with Canvas.ZIndex but I cannot get this particular scenario to work. Just to re-iterate, I would like the gold rectangle to overflow over all of the content in the ContentPresenter, but I would like the border and two squares to remain as they are.
Edit: The source for this project is here if anybody s interested in playing with it.

So you want the middle rectangle to be a part of your border but it should go out of the border bounds?
For this you can only use negative Margin.
In order to overlay the content you border should be the second child of the the parents Grid.
sumarizing everithing we have:
<Style TargetType="local:MyControl">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="local:MyControl">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="100" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<ContentPresenter Grid.Row="1" />
<Border
Grid.Row="0"
BorderBrush="GreenYellow"
BorderThickness="1">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="2*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Rectangle
Grid.Column="0"
Width="50"
Height="50"
HorizontalAlignment="Center"
Fill="Silver" />
<!--Pay attention to Margin="0,0,0,-100"-->
<Rectangle
x:Name="Overflow"
Grid.Column="1"
Width="100"
Height="200"
Margin="0,0,0,-100"
HorizontalAlignment="Center"
Fill="Gold" />
<Rectangle
Grid.Column="2"
Width="50"
Height="50"
HorizontalAlignment="Center"
Fill="Silver" />
</Grid>
</Border>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>

Hacky workaround I came up with - problem is the rectangle is no longer part of the border and as such can't be easily laid out with respect to the border.
<Page
x:Class="Playground.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Playground"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:controls="using:Playground"
mc:Ignorable="d"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Page.Resources>
<Style TargetType="local:MyControl" >
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="local:MyControl">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="100"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<ContentPresenter Grid.Row="1"/>
<Border Grid.Row="0" BorderBrush="GreenYellow" BorderThickness="1">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="2*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Rectangle Grid.Column="0" Width="50" Height="50" Fill="Silver" HorizontalAlignment="Center"/>
<Rectangle Grid.Column="2" Width="50" Height="50" Fill="Silver" HorizontalAlignment="Center"/>
</Grid>
</Border>
<Rectangle Grid.Row="0" Grid.RowSpan="2" x:Name="Overflow" Grid.Column="1" Width="100" Height="200" Fill="Gold" HorizontalAlignment="Center" VerticalAlignment="Top"/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Page.Resources>
<controls:MyControl Grid.Row="0" BorderBrush="Gold" BorderThickness="1">
<Ellipse Fill="Silver"/>
</controls:MyControl>
</Page>

Related

How can I get my ItemsControl on a xaml form to stretch to fit the grid cell?

I'm trying to get my ItemsControl to expand to fit the grid column it is in.
This is what I'm trying to get:
This is what I'm actually getting:
I've tried StackPanel, ViewBox, WrapControl from Microsoft.ToolKit.Uwp.Controls and setting HorizontalAlignment to stretch.
I've tried converting it to a ListView.
Here's my xaml:
<Page
x:Class="PaymentScreen.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:PaymentScreen"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:controls="using:Microsoft.Toolkit.Uwp.UI.Controls"
mc:Ignorable="d">
<Page.DataContext>
<local:PaymentVM></local:PaymentVM>
</Page.DataContext>
<Grid x:Name="MainGrid">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="0.10*"></ColumnDefinition>
<ColumnDefinition Width="0.80*"></ColumnDefinition>
<ColumnDefinition Width="0.10*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="0.15*"></RowDefinition>
<RowDefinition Height="0.30*"></RowDefinition>
<RowDefinition Height="0.65*"></RowDefinition>
</Grid.RowDefinitions>
<Grid Grid.Column="1" Grid.Row="1" HorizontalAlignment="Stretch">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="0.66*"></ColumnDefinition>
<ColumnDefinition Width="0.33*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Border Grid.Column="0" BorderBrush="Red" BorderThickness="1"></Border>
<Border Grid.Column="1" BorderBrush="Red" BorderThickness="1"></Border>
<ItemsControl Grid.Column="0" Grid.Row="1" ItemsSource="{x:Bind ViewModel.PaymentEntryLines}" >
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal"></StackPanel>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate x:DataType="local:PaymentLine" >
<Grid>
<Grid.RowDefinitions>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<TextBox Grid.Row="0" Text="To Pay:"></TextBox>
<TextBox Grid.Row="1" Text="{x:Bind AmountToPay, Mode=TwoWay}"></TextBox>
<TextBox Grid.Row="2" Text="Paid:"></TextBox>
<TextBox Grid.Row="3" Text="{x:Bind AmountPaid, Mode=TwoWay}"></TextBox>
</Grid>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
<Border Grid.Column="1" Grid.Row="1">
<StackPanel>
<Grid>
<Grid.RowDefinitions>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<TextBox Grid.Row="0" Text="To Pay:"></TextBox>
<TextBox Grid.Row="1" Text="300.10"></TextBox>
<TextBox Grid.Row="2" Text="Paid:"></TextBox>
<TextBox Grid.Row="3" Text="500.40"></TextBox>
</Grid>
</StackPanel>
</Border>
</Grid>
</Grid>
</Page>
What you want is an equivalent of the WPF UniformGrid, which divides its client area evenly among its children: Set Rows="1" and it arrange the children horizontally:
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<somens:UniformGrid Rows="1" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
Here is a frequently-recommended UWP implementation of UniformGrid.

WPF Control Background

My WPF control background color is not working in my Universal Windows app. Here is the xaml. The Grid background is working fine, for both grids. The content TextBlocks in the ItemsControl do appear. What am I missing?
<Page
x:Class="Jockusch.Calculator.WindowsStore.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Jockusch.Calculator.WindowsStore"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:system="using:System"
mc:Ignorable="d">
<Page.TopAppBar>
<CommandBar x:Name="TabBar" IsOpen="True" IsSticky="True">
<CommandBar.PrimaryCommands>
<AppBarButton Margin="100,0,0,0" HorizontalAlignment="Left" HorizontalContentAlignment="Right" IsEnabled="True" Name="btnNext" Icon="Next" x:Uid="AppBarNext" Label="Next1"></AppBarButton>
</CommandBar.PrimaryCommands>
</CommandBar>
</Page.TopAppBar>
<Grid Background="Yellow">
<Grid.Resources>
<Style TargetType="ItemsControl">
<Setter Property="Background" Value="Wheat">
</Setter>
</Style>
</Grid.Resources>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="299" />
<ColumnDefinition Width="100"/>
<ColumnDefinition Width="366"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="200"/>
</Grid.RowDefinitions>
<local:WindowsAdAndContentWrapperView Background="Orange" Grid.Row="0" Grid.Column="0" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" x:Name="ContentView"></local:WindowsAdAndContentWrapperView>
<Grid Background="Brown" Grid.Row="0" Grid.Column="1"/>
<ItemsControl Grid.Row="0" Grid.Column="2">
<ItemsControl.Items>
<TextBlock Text="Hello"></TextBlock>
<TextBlock Text="Where are my colors?"/>
</ItemsControl.Items>
</ItemsControl>
</Grid>
</Page>

Wp 8.1 xaml issue

I have TemplatedControl defined as:
<Style TargetType="controls:HeaderedContentControl">
<Setter Property="HintAlignment" Value="Center"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="controls:HeaderedContentControl">
<Grid Background="{TemplateBinding Background}">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition/>
</Grid.RowDefinitions>
<Border Background="Gray">
<TextBlock Text="{TemplateBinding Header}"
FontSize="25"
Foreground="White"
TextWrapping="Wrap"
Margin="0,10"
HorizontalAlignment="Center"
VerticalAlignment="Center"/>
</Border>
<ScrollViewer Grid.Row="1">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition/>
</Grid.RowDefinitions>
<TextBlock Visibility="{Binding Text, RelativeSource={RelativeSource Self}, Converter={StaticResource strConv}}"
Text="{TemplateBinding Hint}"
TextAlignment="{TemplateBinding HintAlignment}"
TextWrapping="Wrap"
Foreground="Gray"
FontSize="17"
Margin="10"/>
<ContentPresenter Content="{TemplateBinding Content}"
Grid.Row="1"/>
</Grid>
</ScrollViewer>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
Sometimes after navigation to the page with this control I see
this
instead of
this
I think this occurs because of BottomAppBar on the page. How can I get round this issue?
Layout where this control is used:
<controls:HeaderedContentControl Header="Регистрация">
<StackPanel Margin="10,40">
<TextBlock Text="Номер телефона:"
FontSize="20"/>
<Grid Margin="0,15">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<TextBlock Text="8"
Margin="10,0"
VerticalAlignment="Center"
FontSize="20"/>
<controls:PhoneTextBox Value="{Binding PhoneNumber, Mode=TwoWay}"
AddContactVisibility="Collapsed"
Margin="0"
Grid.Column="1"/>
</Grid>
<TextBlock Text="Номер вводится без 8-ки. Пример: (XXX)XXX-XX-XX"
FontSize="15"
Foreground="Gray"
TextWrapping="WrapWholeWords"/>
</StackPanel>
</controls:HeaderedContentControl>
<Page.BottomAppBar>
<CommandBar>
<AppBarButton Label="Далее"
Icon="Accept"
Command="{Binding RegisterCommand}"/>
</CommandBar>
</Page.BottomAppBar>

Universal App ListView Item HorizontalAlignment

I would like to create a ListView that has right aligned items as well as left aligned. So far in all my attempts with DataTemplates and ItemContainerStyles, I am not able to get this working. The left alignment works fine as that is the default, but I cannot figure out how to get some items right-aligned. For example, this would be similar to a chat/conversation type view like the Windows Phone Messaging app.
My current XAML looks like this:
<Page
x:Class="MDControl.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:MDControl"
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="Messages" Source="{Binding mMessages}"/>
<DataTemplate x:Key="SentMessageTemplate">
<StackPanel Padding="10" Margin="5" Background="Teal" HorizontalAlignment="Right" Width="Auto">
<TextBlock Text="{Binding MessageType}" FontWeight="Bold" TextWrapping="NoWrap" Foreground="White"/>
<TextBlock Text="{Binding MessageBody}" TextWrapping="Wrap" Foreground="White" />
<TextBlock Text="{Binding Timestamp}" TextWrapping="NoWrap" Foreground="White" FontStyle="Italic" FontSize="12"/>
</StackPanel>
</DataTemplate>
<DataTemplate x:Key="ReceivedMessageTemplate">
<StackPanel Padding="10" Margin="5" Background="LightGray">
<TextBlock Text="{Binding MessageType}" FontWeight="Bold" TextWrapping="NoWrap"/>
<TextBlock Text="{Binding MessageBody}" TextWrapping="Wrap"/>
<TextBlock Text="{Binding Timestamp}" TextWrapping="NoWrap" TextAlignment="Right" FontStyle="Italic" FontSize="12"/>
</StackPanel>
</DataTemplate>
<Style TargetType="ListViewItem" x:Key="SentMessageStyle">
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
</Style>
<Style TargetType="ListViewItem" x:Key="ReceivedMessageStyle">
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
</Style>
<local:MessageListTemplateSelector x:Key="MessageListTemplateSelector"
SentMessageTemplate="{StaticResource SentMessageTemplate}"
ReceivedMessageTemplate="{StaticResource ReceivedMessageTemplate}">
</local:MessageListTemplateSelector>
<local:MessageListContainerStyleSelector x:Key="MessageListContainerStyleSelector"
SentMessageStyle="{StaticResource SentMessageStyle}"
ReceivedMessageStyle="{StaticResource ReceivedMessageStyle}">
</local:MessageListContainerStyleSelector>
</Page.Resources>
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<ListView x:Name="messageList" ScrollViewer.VerticalScrollBarVisibility="Visible" ItemContainerStyleSelector="{StaticResource MessageListContainerStyleSelector}" ItemsSource="{Binding Source={StaticResource Messages}}" ItemTemplateSelector="{StaticResource MessageListTemplateSelector}" Margin="10,120,10,50" VerticalAlignment="Bottom" IsDoubleTapEnabled="False"/>
</Grid>
What can I change to get the "Sent" messages to be right aligned? Currently they show up with a Teal background which I want, but they are still Left aligned instead of Right. I am a little new to XAML, so forgive me if I'm way off here.
UPDATE: Solution
Grids were the key, I ended up having to use multiple grids to achieve the correct right-alignment, in conjunction with an ItemContainerStyle setting the HorizontalContentAlignment.
<Page
x:Class="MDControl.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:MDControl"
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="Messages" Source="{Binding mMessages}"/>
<DataTemplate x:Key="SentMessageTemplate">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid Height="Auto" Grid.Row="1" Margin="5" HorizontalAlignment="Right">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<StackPanel Padding="10" Background="Teal">
<TextBlock Text="{Binding MessageType}" FontWeight="Bold" TextWrapping="NoWrap" Foreground="White" />
<TextBlock Text="{Binding MessageBody}" TextWrapping="Wrap" Foreground="White" />
<TextBlock Text="{Binding Timestamp}" TextWrapping="NoWrap" Foreground="White" FontStyle="Italic" FontSize="12" HorizontalAlignment="Right"/>
</StackPanel>
</Grid>
</Grid>
</DataTemplate>
<DataTemplate x:Key="ReceivedMessageTemplate">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid Height="Auto" Grid.Row="1" Margin="5" HorizontalAlignment="Left">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<StackPanel Padding="10" Background="LightGray">
<TextBlock Text="{Binding MessageType}" FontWeight="Bold" TextWrapping="NoWrap" />
<TextBlock Text="{Binding MessageBody}" TextWrapping="Wrap" />
<TextBlock Text="{Binding Timestamp}" TextWrapping="NoWrap" FontStyle="Italic" FontSize="12" HorizontalAlignment="Right"/>
</StackPanel>
</Grid>
</Grid>
</DataTemplate>
<local:MessageListTemplateSelector x:Key="MessageListTemplateSelector"
SentMessageTemplate="{StaticResource SentMessageTemplate}"
ReceivedMessageTemplate="{StaticResource ReceivedMessageTemplate}">
</local:MessageListTemplateSelector>
</Page.Resources>
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<ListView x:Name="messageList" ScrollViewer.VerticalScrollBarVisibility="Visible" ItemsSource="{Binding Source={StaticResource Messages}}" ItemTemplateSelector="{StaticResource MessageListTemplateSelector}" Margin="10,120,10,50" VerticalAlignment="Bottom" IsDoubleTapEnabled="False">
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
</Style>
</ListView.ItemContainerStyle>
</ListView>
</Grid>
The problem is in your DataTemplates , not in styles or etc.You must use Grid instead of Stackpanel in your DataTemplate to achieve that.
Stackpanels won't stretch to parent.They'll only get the width / height of all controls inside it.Try something like
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
You should use HorizontalAlignment property which defines the position of the element inside a parent element.<Grid x:Name="simpleGrid" height = 50 width = 100 HorizontalAlignment="right" />

Silverlight AG_E_UNKOWN_ERROR UserControl Apps.xml Template

Ive created a simple usercontrol and even though the app runs ok applying the template to
I am defining the Control Template here
App.xaml
<Application xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="ResourcesCountDown.App"
>
<Application.Resources>
<ControlTemplate x:Key="myWindowTemplate">
<Grid x:Name="myGrid" Background="Black" Width="50" Height="50">
<ContentPresenter Name="Content"></ContentPresenter>
</Grid>
</ControlTemplate>
</Application.Resources>
</Application>
My UserControl Test.xaml
<UserControl x:Class="ResourcesCountDown.Test"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Width="100" Height="100" >
<Grid x:Name="LayoutRoot">
<Button Name="myButton" Template="{StaticResource myWindowTemplate}" Foreground="White" Content="CLICK" ></Button>
</Grid>
</UserControl>
My page where the user control is being used and the page where the AG E UNKOWN_ERROR occurs.
If I remove applying the template from test.xaml and remove the Template="{StaticResource myWindowTemplate}" the error goes away, so I know its something BAD in my template definition?
Mainpage.xaml
<UserControl x:Class="ResourcesCountDown.Mainpage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:ResourcesCountDown="clr-namespace:ResourcesCountDown"
xmlns:sliverlightControls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Toolkit"
Width="Auto" Height="Auto" Name="mainPage"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d">
<Grid x:Name="LayoutRoot" Background="White" ShowGridLines="False" >
<Grid.ColumnDefinitions>
<ColumnDefinition Width="10"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="10"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="10"/>
<RowDefinition Height="80"/>
<RowDefinition Height="10"/>
<RowDefinition Height="*"/>
<RowDefinition Height="10"/>
</Grid.RowDefinitions>
<Border Grid.Column="1" Grid.Row="1" Height="Auto" VerticalAlignment="Top" CornerRadius="5">
<Border.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#FFFFAA01"/>
<GradientStop Color="#FFFD6900" Offset="1"/>
</LinearGradientBrush>
</Border.Background>
<Grid x:Name="TopBannerGrid">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="300"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="500"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<ResourcesCountDown:LogoControl Width="Auto" Height="Auto" Grid.ColumnSpan="2" Margin="5,0,0,0"/>
<ResourcesCountDown:MenuControl Grid.Column="2" HorizontalAlignment="Right" x:Name="menu" Margin="0,-30,0,0"/>
</Grid>
</Border>
<sliverlightControls:WrapPanel Width="900" Height="600" Grid.Column="1" Grid.Row="3" Orientation="Vertical" HorizontalAlignment="Left" VerticalAlignment="Top" >
<ResourcesCountDown:noteControl Width="200" Height="200" headingText="Whats it about?" Margin="10"
noteText="We have one planet with finite resources. This web site was created to try and express the resource consumption.">
</ResourcesCountDown:noteControl>
<ResourcesCountDown:noteControl Width="200" Height="200" headingText="Latest News" Margin="10"
noteText="This week we have see some many new news in just a short time">
</ResourcesCountDown:noteControl>
<ResourcesCountDown:RSSFeed Width="600" Height="200" Margin="10" headingText="Hot News"/>
<ResourcesCountDown:datagridControl Width="600" Height="100" x:Name="theDataGrid" Margin="10" headingText="Stats" > </ResourcesCountDown:datagridControl>
<ResourcesCountDown:Test></ResourcesCountDown:Test>
</sliverlightControls:WrapPanel>
</Grid>
</UserControl>
I think you need a TargetType="Grid" on your <ControlTemplate>:
<ControlTemplate x:Key="myWindowTemplate TargetType="Grid">
....
Also, Grid isn't a ContentControl so I don't think the ContentPresenter you put in the template will behave the way you expect - it could even be causing the error.
Actually, from the code you've posted, your TargetType should be Button because you're applying the template to button.