我有一個XAML ResourceDictionary,我嘗試爲我的程序中的所有按鈕定義一致的設計。當鼠標光標在其上時,XAML按鈕模板發生更改
我設法讓一個單一的設計對他們來說,有了這個代碼:
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Style TargetType="{x:Type Button}">
<Setter Property="OverridesDefaultStyle" Value="True" />
<Setter Property="SnapsToDevicePixels" Value="True" />
<Setter Property="Foreground" Value="MidnightBlue" />
<Setter Property="Background" Value="White" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate x:Name="tmpltButton">
<Grid>
<Border x:Name="ButtonBorder"
CornerRadius="7,7,7,7"
BorderBrush="MidnightBlue"
BorderThickness="2">
</Border>
<ContentPresenter x:Name="ButtonContent"
Content="{Binding Path=Content,
RelativeSource={RelativeSource TemplatedParent}}"
HorizontalAlignment="center"
VerticalAlignment="center">
</ContentPresenter>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>
但它刪除,當用戶CLIK按鈕,或把他的鼠標在它的默認行爲。儘管我努力想找回一種方法,但我找不到方法。
當鼠標懸停時,如何更改按鈕設計?
值得一提的是,你只能**編輯Visual Studio中**文檔大綱窗口**的副本**。否則,您可以使用** Expression Blend **設計器。 –
謝謝。我試圖將你的代碼添加到我的,但我得到一個錯誤: 未知的構建錯誤,MC4109:無法找到類型'System.Windows.Controls.Control'的模型屬性'默認'。我不確定發生了什麼事。也許這是因爲我使用VS2010。 – MarinD
也許你是針對不同的框架版本和'IsDefaulted'屬性不存在,請嘗試刪除它。 – fillobotto