2011-06-21 58 views
0

這個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="{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> 

回答

1

您正試圖在Trigger中設置Background屬性,但Ellipse沒有Background屬性。它有一個Fill財產。所以你需要使用:

<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> 
相關問題