Silverlight AG_E_UNKOWN_ERROR UserControl Apps.xml模板

时间:2009-06-12 11:07:27

标签: silverlight user-controls templates

我创建了一个简单的用户控件,即使应用程序运行正常,也可以将模板应用到

我在这里定义控制模板

的App.xaml     

    <ControlTemplate x:Key="myWindowTemplate">
        <Grid x:Name="myGrid" Background="Black" Width="50" Height="50">
            <ContentPresenter Name="Content"></ContentPresenter>
        </Grid>
    </ControlTemplate>

</Application.Resources>

我的用户控制

Test.xaml

<Grid x:Name="LayoutRoot">
    <Button Name="myButton" Template="{StaticResource myWindowTemplate}" Foreground="White" Content="CLICK" ></Button>
</Grid>

我正在使用用户控件的页面以及发生AG E UNKOWN_ERROR的页面。 如果我从test.xaml删除应用模板并删除Template =“{StaticResource myWindowTemplate}”,则错误消失,所以我知道它在我的模板定义中有什么不好???

MainPage.xaml中

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” &GT;

<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>

2 个答案:

答案 0 :(得分:0)

我认为您需要<ControlTemplate>上的TargetType =“网格”:

<ControlTemplate x:Key="myWindowTemplate TargetType="Grid">

...

此外,Grid不是ContentControl,因此我不认为您放入模板中的ContentPresenter会按照您期望的方式运行 - 它甚至可能导致错误。

答案 1 :(得分:0)

实际上,从您发布的代码中,您的TargetType应该是Button,因为您正在将模板应用于按钮。