wpf表示不显示图像

时间:2015-08-30 19:19:24

标签: c# css wpf visual-studio

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

希望得到帮助!!

1 个答案:

答案 0 :(得分:-1)

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