2015-08-30 77 views
2

我使用VS 2013和設計一個WPF窗體。問題是當我設計的按鈕與圖像完美顯示,但是當我運行該項目時,它不顯示按鈕上方的圖像。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> 

希望尋求幫助!

+0

我想你應該檢查你的圖像來源 – AleshaOleg

+0

我已經檢查過它們。它們都是正確的 – tabia

+0

右鍵單擊圖像,屬性並將它們設置爲內容。您還需要設置它們應該被複制到輸出目錄。 – Filip

回答

-1

我清除了保證金,這對我來說還可以!
使用保證金不是分層的好方法! 對於分層最好使用分層元素。例如StackPanel等。