如何在按钮内制作图像,以便在使用Width和单击它时使其更大Height。
我的按钮 XAML 代码是这样的:
<Button x:Name="Input2" Grid.Row="0" MouseEnter="Input2_MouseEnter" MouseLeave="Input2_MouseLeave" Click="Input2_Click" Background="{x:Null}" BorderBrush="{x:Null}" Foreground="{x:Null}">
<Button.Template>
<ControlTemplate>
<Border HorizontalAlignment="Center" VerticalAlignment="Center" >
<Image Source= "C:\input.png"
Width="40"
Height="40"/>
</Border>
</ControlTemplate>
</Button.Template>
</Button>
Run Code Online (Sandbox Code Playgroud)
Input2.Height- 更改按钮的大小,而不是按钮内的图像。
我的 C# 代码:
private void Input2_Click(object sender, RoutedEventArgs e)
{
// What to do here?
}
Run Code Online (Sandbox Code Playgroud)
最好在按钮的属性上使用触发器,而不是附加 Click 事件处理程序IsPressed:
<Button>
<Button.Template>
<ControlTemplate TargetType="Button">
<Border>
<Image x:Name="image" Width="40" Height="40" Source="C:\input.png"/>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsPressed" Value="True">
<Setter TargetName="image" Property="Width" Value="50"/>
<Setter TargetName="image" Property="Height" Value="50"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Button.Template>
</Button>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
710 次 |
| 最近记录: |