Lam*_*awy 26 c# button cursor visual-studio-2013 windows-8.1
我想将鼠标悬停在按钮上时将光标更改为手,例如,我有这个按钮:
<Button Content="" HorizontalAlignment="Left" Margin="229,128,0,0" VerticalAlignment="Top" Height="107" Width="170" Grid.RowSpan="2">
<Button.Template>
<ControlTemplate TargetType="Button">
<Grid>
<Grid.Background>
<ImageBrush ImageSource="africa/picture17.png"/>
</Grid.Background>
<ContentPresenter/>
</Grid>
</ControlTemplate>
</Button.Template>
</Button>
Run Code Online (Sandbox Code Playgroud)
当我将鼠标悬停在按钮上时如何将光标更改为手?我正在使用Visual Studio 2013 for Windows Store 8和C#-XAML.
gle*_*eng 78
您可以通过更改Cursor属性来执行此操作:
<Button Cursor="Hand" .../>
Run Code Online (Sandbox Code Playgroud)
Bri*_*oll 11
您需要使用Mouse.OverrideCursor:
myButton.MouseEnter += (s,e) => Mouse.OverrideCursor = Cursors.Hand;
myButton.MouseLeave += (s,e) => Mouse.OverrideCursor = Cursors.Arrow;
Run Code Online (Sandbox Code Playgroud)
使用 Visual State Manager
更新你的XAML样子
<Button Content="Beh}" Style="{StaticResource ButtonHover}">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Normal"/>
<VisualState x:Name="MouseOver">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Cursor)">
<DiscreteObjectKeyFrame KeyTime="00:00:00">
<DiscreteObjectKeyFrame.Value>
<Cursor>Hand</Cursor>
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
</Button>
Run Code Online (Sandbox Code Playgroud)
小智 9
您需要使用Style按钮,是否可以在窗口资源或按钮的样式中编写:
<Style>
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Cursor" Value="Hand"/>
</Trigger>
</Style.Triggers>
</Style>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
37390 次 |
| 最近记录: |