如何更改懸停和點擊上的按鈕的背景圖像? Visual Studio的UI似乎沒有提供任何簡單的方法。目前,默認行爲似乎用純色看起來很乾淨的我的圖像。在懸停或點擊更改按鈕圖像
所有我至今是鈕基座:
<Button Content="" Height="75" VerticalAlignment="Center" Width="75" HorizontalAlignment="Center" ClickMode="Press">
<Button.Background>
<ImageBrush ImageSource="../data/images/icons/skill_icon_0.png"/>
</Button.Background>
</Button>
我試圖處理事件和手動設置,但它並不適用於壓制/發行工作:
Button skillButton = new Button();
skillButton.Width = 75;
skillButton.Height = 75;
skillButton.ClickMode = ClickMode.Press;
skillButton.Background = GetIconImage(iconIndex, 0);
skillButton.PointerEntered +=
(object sender, Windows.UI.Xaml.Input.PointerEventArgs e) => {
skillButton.Background = GetIconImage(iconIndex, 1);
};
skillButton.PointerExited +=
(object sender, Windows.UI.Xaml.Input.PointerEventArgs e) => {
skillButton.Background = GetIconImage(iconIndex, 0);
};
skillButton.PointerPressed +=
(object sender, Windows.UI.Xaml.Input.PointerEventArgs e) => {
skillButton.Background = GetIconImage(iconIndex, 2);
};
skillButton.PointerReleased +=
(object sender, Windows.UI.Xaml.Input.PointerEventArgs e) => {
if (skillButton.FocusState == FocusState.Pointer)
skillButton.Background = GetIconImage(iconIndex, 1);
else skillButton.Background = GetIconImage(iconIndex, 0);
};
因此,唯一能做到的方法實際上是有代碼響應事件並手動更改它? –
因爲我知道是的:)但可能是有另一種解決方案,但我從來沒有看到它:) –
我試過了,它適用於進入和退出,但按下並釋放不起作用。 –