C# 控件模板不显示网格

C# 控件模板不显示网格,c#,wpf,xaml,controltemplate,C#,Wpf,Xaml,Controltemplate,我试图创建一个包含网格的按钮,其中的行包含特定文本 按钮将有两行,两行都有不同的文本。将显示传递给控制模板的文本,但不显示模板中指定的文本 此外,网格行的高度也不会显示。我想让它扩大按钮的高度。事实上,我不确定网格是否真的显示出来 <Window x:Class="MAQButtonTest.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:

我试图创建一个包含网格的
按钮
,其中的行包含特定文本

按钮将有两行,两行都有不同的文本。将显示传递给
控制模板的文本,但不显示模板中指定的文本

此外,网格行的高度也不会显示。我想让它扩大按钮的高度。事实上,我不确定网格是否真的显示出来

<Window x:Class="MAQButtonTest.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="695" Width="996">        
    <Window.Resources>
        <Style TargetType="TextBlock">
            <Setter Property="OverridesDefaultStyle" Value="True"/>
        </Style>
        <ControlTemplate TargetType="Control" x:Key="1">
            <Grid Width="444">
                <Grid.RowDefinitions>
                    <RowDefinition Height="51" />
                    <RowDefinition Height="36" />
                </Grid.RowDefinitions>
                <Grid Grid.Row="0" Background="#286c97">
                    <TextBlock>This is the first piece of text</TextBlock>
                </Grid>
                <Grid Grid.Row="1" Background="#5898c0">
                    <ContentPresenter Grid.Row="0" />
                </Grid>
            </Grid>
        </ControlTemplate>
    </Window.Resources>
    <Grid>

        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="300" />
            <ColumnDefinition />
        </Grid.ColumnDefinitions>
        <Grid Grid.Column="0" Background="#e9f1f6"></Grid>
        <Grid Grid.Column="1" Background="#d2e3ed">
            <StackPanel>
                <TextBlock FontFamily="Segoe UI" FontSize="22" FontWeight="Medium" Margin="52,58,0,0" Foreground="#0c3d5d">Your Quizzes <TextBlock FontFamily="Segoe UI" FontSize="18" FontWeight="Medium" Foreground="#0c3d5d">(7)</TextBlock></TextBlock>
                <Grid>
                    <Button Width="444" Background="{x:Null}" BorderThickness="0" Style="{StaticResource {x:Static ToolBar.ButtonStyleKey}}">
                        <TextBlock>This is a second piece of text</TextBlock>
                    </Button>
                </Grid>
            </StackPanel>
        </Grid>

    </Grid>
</Window>

这是第一段文字
你的测验(7)
这是第二段文字
以下是目前我试图实现的按钮布局的粗略说明:


为什么要使用TargetType作为“控件”,请使用按钮。您需要定义一个按钮。使用“混合”编辑按钮模板,从中删除所有不必要的内容。

您正在设置按钮的样式,而此时您应该设置模板

资源:

    <ControlTemplate TargetType="Button" x:Key="ButtonTemplate">
        <Grid Width="444">
            <Grid.RowDefinitions>
                <RowDefinition Height="51" />
                <RowDefinition Height="36" />
            </Grid.RowDefinitions>
            <Grid Grid.Row="0" Background="#286c97">
                <TextBlock>This is the first piece of text</TextBlock>
            </Grid>
            <Grid Grid.Row="1" Background="#5898c0">
                <ContentPresenter />
            </Grid>
        </Grid>
    </ControlTemplate>

这是第一段文字
和按钮:

    <Button Template="{StaticResource ButtonTemplate}" >
        Text 2
    </Button>

文本2

哎哟,我没意识到我还在里面。我已将其更改为button,它仍以完全相同的方式显示:/