我正在使用VS 2013并设计WPF表单。问题是,当我设计带有图像的按钮时,它可以完美显示,但是当我运行项目时,它不会在按钮上显示图像。
码
<Button x:Name="btnCommunication" Margin="428,138,448,338" Click="btnCommunication_Click" Width="Auto" Foreground="#FF007EFF">
<Button.Style>
<Style TargetType="{x:Type Button}">
<Setter Property="Background" Value="Purple"/>
<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="IsMouseOver" Value="True">
<Setter Property="Background" Value="GreenYellow"/>
</Trigger>
</Style.Triggers>
</Style>
</Button.Style>
<Grid VerticalAlignment="Center" HorizontalAlignment="Left" Height="236" Width="350">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Image Grid.Column="0" Margin="0,0,-80,41" Source="Images/communication.png" Width="135" Height="195" HorizontalAlignment="Center" VerticalAlignment="Center" RenderTransformOrigin="0.525,0.37" />
<TextBlock Grid.Column="1" Margin="0,174,-128,30" Text="Communication Mode" HorizontalAlignment="Center" VerticalAlignment="Center" Foreground="White" FontSize="28" Grid.ColumnSpan="2"/>
</Grid>
</Button>
希望获得帮助!
最佳答案
我清除了保证金,这对我来说还行!
使用边距不是分层的好方法!
对于分层,最好使用分层元素,例如StackPanel等。