IT박스

이미지가있는 WPF 버튼

itboxs 2020. 8. 16. 19:57
반응형

이미지가있는 WPF 버튼


WPF의 버튼에 이미지를 첨부하려고하는데이 코드는 실패합니다. 유사한 코드가 Mozilla XUL에서 완벽하게 작동하면 이상하게 보입니다.

<Button Height="49.086" Margin="3.636,12,231.795,0" Name="button2" 
        VerticalAlignment="Top" Grid.Column="1" Click="button2_Click" 
        Source="Pictures/apple.jpg">Disconnect from Server</Button>

대신 다음과 같이하고 싶습니다.

<Button>
    <StackPanel>
        <Image Source="Pictures/apple.jpg" />
        <TextBlock>Disconnect from Server</TextBlock>
    </StackPanel>
</Button>

이미지를 전체 버튼으로 늘리는 또 다른 방법입니다. 아래 코드를 시도해 볼 수 있습니다.

<Grid.Resources>
  <ImageBrush x:Key="AddButtonImageBrush" ImageSource="/Demoapp;component/Resources/AddButton.png" Stretch="UniformToFill"/>
</Grid.Resources>

<Button Content="Load Inventory 1" Background="{StaticResource AddButtonImageBrush}"/> 

여기 에서 참조

또한 다른 도움이 될 수 있습니다. 여기에 MouseOver Option 과 동일한 내용을 게시했습니다 .


<Button x:Name="myBtn_DetailsTab_Save" FlowDirection="LeftToRight"  HorizontalAlignment="Left" Margin="835,544,0,0" VerticalAlignment="Top"  Width="143" Height="53" BorderBrush="#FF0F6287" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" FontFamily="B Titr" FontSize="15" FontWeight="Bold" BorderThickness="2" Click="myBtn_DetailsTab_Save_Click">
    <StackPanel HorizontalAlignment="Stretch" Background="#FF1FB3F5" Cursor="Hand" >
        <Image HorizontalAlignment="Left"  Source="image/bg/Save.png" Height="36" Width="124" />
        <TextBlock HorizontalAlignment="Center" Width="84" Height="22" VerticalAlignment="Top" Margin="0,-31,-58,0" Text="ثبت مشتری" />
    </StackPanel>
</Button>

이게 제대로 돼야하지?

<Button Content="Test">
    <Button.Background>
        <ImageBrush ImageSource="folder/file.PNG"/>
    </Button.Background>
</Button>

참고 URL : https://stackoverflow.com/questions/2697383/wpf-button-with-image

반응형