1
我正在學習WPF模板,我正在創建一個按鈕。我正在使用觸發器來更改'IsMouseOver'上橢圓的填充屬性。當我將觸發器直接設置爲「填充」屬性時,它可以工作。但是當我嘗試引用特定的SolidColorBrush時,出現編譯錯誤。這個觸發器有什麼問題?
這工作:
<ControlTemplate x:Key="GhostButtonTemplate" TargetType="Button">
<Grid>
<Ellipse Name="Border" Stroke="DarkGray" Fill="Gray">
</Ellipse>
<ContentPresenter ... />
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="Border" Property="Fill" Value="Black"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
這將導致錯誤:
<ControlTemplate x:Key="GhostButtonTemplate" TargetType="Button">
<Grid>
<Ellipse Name="Border" Stroke="DarkGray">
<Ellipse.Fill>
<SolidColorBrush Color="Gray" x:Name="FillBrush"/>
</Ellipse.Fill>
</Ellipse>
<ContentPresenter ... />
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="FillBrush" Property="Color" Value="Black"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
錯誤是:
Cannot find the Trigger target 'FillBrush'. (The target must appear before any Setters,Triggers, or Conditions that use it.)
任何人都可以解釋爲什麼第二種情況下不能正常工作?謝謝。
什麼東西有點比黑色更復雜? – Li3ro 2015-12-13 12:50:23