如何将 mahapps 方法绑定到按钮 属性?
How can I bind a mahapps method to a button property?
我仍在努力学习 WPF 和 XAML,以及 MvvM 和 Prism。
我将 MahApps 与 Prism 一起使用,并在按钮中嵌入了一个图标。我想在鼠标悬停在图标上时调用此图标上的“旋转”方法。
我该怎么做?
代码如下:
<Grid Background="#52514e">
<StackPanel HorizontalAlignment="Left" Orientation="Vertical">
<CheckBox Content="CanExecute" IsChecked="{Binding CanExecute}"></CheckBox>
<Button x:Name="TestButton" Command="{Binding ClickCommand}" Background="#52514e" Height="35" Width="35" BorderThickness="0" ToolTip=" Marks the current work order as complete.">
<Button.Style>
<Style TargetType="Button">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Border Background="{TemplateBinding Background}">
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<Trigger Property="IsEnabled" Value="False">
<Setter Property="Foreground" Value="Gray"></Setter>
</Trigger>
<Trigger Property="Button.IsMouseOver" Value="True">
<Setter Property="Foreground" Value="Yellow"></Setter>
</Trigger>
</Style.Triggers>
</Style>
</Button.Style>
<iconPacks:Unicons Width="35" Height="35" Kind="Cog" Spin="True"/>
</Button>
<TextBlock Text="{Binding Title}"></TextBlock>
</StackPanel>
</Grid>
iconPacks:Unicons
元素是标记扩展而非控件。请改用 PackIconUnicons
控件并将 Spin
属性 绑定到父按钮的 IsMouseOver
属性。
<iconPacks:PackIconUnicons Width="35" Height="35" Kind="Cog" Spin="{Binding IsMouseOver, RelativeSource={RelativeSource AncestorType={x:Type Button}}}"/>
我仍在努力学习 WPF 和 XAML,以及 MvvM 和 Prism。
我将 MahApps 与 Prism 一起使用,并在按钮中嵌入了一个图标。我想在鼠标悬停在图标上时调用此图标上的“旋转”方法。
我该怎么做?
代码如下:
<Grid Background="#52514e">
<StackPanel HorizontalAlignment="Left" Orientation="Vertical">
<CheckBox Content="CanExecute" IsChecked="{Binding CanExecute}"></CheckBox>
<Button x:Name="TestButton" Command="{Binding ClickCommand}" Background="#52514e" Height="35" Width="35" BorderThickness="0" ToolTip=" Marks the current work order as complete.">
<Button.Style>
<Style TargetType="Button">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Border Background="{TemplateBinding Background}">
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<Trigger Property="IsEnabled" Value="False">
<Setter Property="Foreground" Value="Gray"></Setter>
</Trigger>
<Trigger Property="Button.IsMouseOver" Value="True">
<Setter Property="Foreground" Value="Yellow"></Setter>
</Trigger>
</Style.Triggers>
</Style>
</Button.Style>
<iconPacks:Unicons Width="35" Height="35" Kind="Cog" Spin="True"/>
</Button>
<TextBlock Text="{Binding Title}"></TextBlock>
</StackPanel>
</Grid>
iconPacks:Unicons
元素是标记扩展而非控件。请改用 PackIconUnicons
控件并将 Spin
属性 绑定到父按钮的 IsMouseOver
属性。
<iconPacks:PackIconUnicons Width="35" Height="35" Kind="Cog" Spin="{Binding IsMouseOver, RelativeSource={RelativeSource AncestorType={x:Type Button}}}"/>