【问题标题】:Silverlight AG_E_UNKOWN_ERROR UserControl Apps.xml TemplateSilverlight AG_E_UNKOWN_ERROR UserControl Apps.xml 模板
【发布时间】:2009-06-12 11:07:27
【问题描述】:

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

我在这里定义控制模板

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>

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

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

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>

【问题讨论】:

    标签: xaml templates silverlight user-controls


    【解决方案1】:

    我认为您的&lt;ControlTemplate&gt; 上需要一个 TargetType="Grid":

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

    ....

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

    【讨论】:

      【解决方案2】:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多