gpt4 book ai didi

c# - wpf 表单不显示图像

转载 作者:太空宇宙 更新时间:2023-11-03 17:01:03 25 4
gpt4 key购买 nike

我正在使用 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>

希望得到帮助!!

最佳答案

我清除了 margin ,这对我来说没问题!
使用边距不是分层的好方法!对于分层,最好使用分层元素。例如StackPanel等。

关于c# - wpf 表单不显示图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32300243/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com