Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/428.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
为什么下面的xaml代码不起作用?_Xaml - Fatal编程技术网

为什么下面的xaml代码不起作用?

为什么下面的xaml代码不起作用?,xaml,Xaml,为什么这个xaml代码不起作用 <Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> <Grid> <Grid.Resources> <ControlTemplate x:Key="btnTemplate" TargetType

为什么这个xaml代码不起作用

<Page
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  <Grid>  
  <Grid.Resources>
    <ControlTemplate x:Key="btnTemplate" TargetType="{x:Type Button}">
      <Grid>
       <Ellipse Name="el1" Fill="Orange" Width="100" Height="100" />
       <ContentPresenter VerticalAlignment="Center" HorizontalAlignment="Center" /> 
      </Grid>
    <ControlTemplate.Triggers>
      <Trigger Property="Button.IsMouseOver" Value="True">
        <Setter TargetName="el1" Property="Background" Value="Blue" />
      </Trigger>
    </ControlTemplate.Triggers>
    </ControlTemplate>
  </Grid.Resources>
  <Button Content="Klick mich" Template="{StaticResource btnTemplate}"/>
  </Grid>
</Page>

您试图在触发器中设置背景属性,但椭圆没有背景属性。它有一个属性。因此,您需要使用:

<Grid>
    <Grid.Resources>
        <ControlTemplate x:Key="btnTemplate" TargetType="{x:Type Button}">
            <Grid>
                <Ellipse Name="el1" Fill="Orange" Width="100" Height="100" />
                <ContentPresenter VerticalAlignment="Center" HorizontalAlignment="Center" />
            </Grid>
            <ControlTemplate.Triggers>
                <Trigger Property="Button.IsMouseOver" Value="True">
                    <Setter TargetName="el1" Property="Fill" Value="Blue" />
                </Trigger>
            </ControlTemplate.Triggers>
        </ControlTemplate>
    </Grid.Resources>
    <Button Content="Klick mich" Template="{StaticResource btnTemplate}" />
</Grid>