【问题标题】:wpf forms not displaying imageswpf表单不显示图像
【发布时间】:2015-08-30 19:19:23
【问题描述】:

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

希望得到帮助!!

【问题讨论】:

  • 我认为你应该检查你的图片来源
  • 我已经检查过了。他们都是正确的
  • 右击图片、属性并将其设置为内容。您还需要设置它们应该被复制到输出目录。
  • 谢谢 :) 成功了(y)

标签: c# css wpf visual-studio


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2015-09-08
    • 2021-01-08
    • 2010-12-16
    • 2014-11-03
    • 2011-09-19
    • 1970-01-01
    • 1970-01-01
    • 2011-01-08
    • 1970-01-01
    相关资源
    最近更新 更多