Izmail360
Izmail360

Reputation: 89

C# WPF - button picture looks differently on Windows 7 and Windows 10

I am trying to build application which has some pictures drawn on buttons. Application looks nice on Windows 7 - as expected, although on Windows 10 it looks differently.

Despite Defined width and height size, image is truncated.

Uploaded screens:

1: Windows 7 vs. Windows 10

Windows 7 vs. Windows 10[1]

2: Windows 7 vs. Windows 10

enter image description here]2

<Menu x:Name="menu" HorizontalAlignment="Stretch" Height="25" Margin="0,0,0,0" VerticalAlignment="Center" Width="Auto" DockPanel.Dock="Top">
                <MenuItem Header="_Soubor" Height="25" HorizontalAlignment="Center" VerticalAlignment="Center">
                    <MenuItem Click="NewCalculation_Click">
                        <MenuItem.Header>
                            <TextBlock Text="_Nová kalkulace" VerticalAlignment="Center"/>
                        </MenuItem.Header>
                        <MenuItem.Icon>
                            <Image Source="graphics/icons/new.ico" Height="35" Width="35" />
                        </MenuItem.Icon>
                    </MenuItem>
                    <Separator/>
                    <MenuItem Click="saveCalculation_Click">
                        <MenuItem.Header>
                            <TextBlock Text="Uložit kalkulaci" VerticalAlignment="Center"></TextBlock>
                        </MenuItem.Header>
                        <MenuItem.Icon>
                            <Image Source="graphics/icons/save.ico" Height="35" Width="35"  />
                        </MenuItem.Icon>
                    </MenuItem>
                    <MenuItem Click="LoadCalculation_Click">
                        <MenuItem.Header>
                            <TextBlock Text="Načíst kalkulaci" VerticalAlignment="Center"></TextBlock>
                        </MenuItem.Header>
                        <MenuItem.Icon>
                            <Image Source="graphics/icons/load.ico" Height="35" Width="35" />
                        </MenuItem.Icon>
                    </MenuItem>
                    <Separator/>
                    <MenuItem Click="createReport_Click">
                        <MenuItem.Header >
                            <TextBlock Text="Vytvoř report" VerticalAlignment="Center"></TextBlock>
                        </MenuItem.Header>
                        <MenuItem.Icon>
                            <Image Source="graphics/icons/report.ico" Height="35" Width="35"  />
                        </MenuItem.Icon>
                    </MenuItem>
                    <Separator/>
                    <MenuItem Click="endApp_Click">
                        <MenuItem.Header>
                            <TextBlock Text="Konec" VerticalAlignment="Center"></TextBlock>
                        </MenuItem.Header>
                        <MenuItem.Icon>
                            <Image Source="graphics/icons/close.ico" Height="35" Width="35"  />
                        </MenuItem.Icon>
                    </MenuItem>
                </MenuItem>
                <MenuItem Header="_Nastavení" Height="25" HorizontalAlignment="Center" VerticalAlignment="Center">
                    <MenuItem x:Name="MenuSqlSetting" Header="_Připojení na SQL server" Click="MenuSqlSetting_Click"/>
                </MenuItem>
                <MenuItem Header="_O aplikaci" Click="MenuItem_Click" />
            </Menu>

Code for second screen:

<Button x:Name="buttonRemove" Grid.Column="1"  Margin="2,0,0,0" IsEnabled="False" Click="buttonRemove_Click" Background="White">
    <StackPanel>
        <Image Source="Graphics/remove.png" Width="50" Height="50"/>
    </StackPanel>
</Button>

Thanks for any advice.

Upvotes: 0

Views: 1317

Answers (2)

giuliohome
giuliohome

Reputation: 1

There is another workaround from Visual Studio. You click with the mouse on the MenuItem and you look at the Template in the Property Inspector under the Miscellaneous group. Then you "Convert to New Resource..."

see the image

so you will get the corresponding xaml transformed as

<MenuItem Command="{Binding YourCmd}" Header="Your Header" 
    Template="{DynamicResource MenuItemControlTemplate1}" >

Then you can build on your Windows 7 machine and deploy to Windows 10 without such issue.

Upvotes: 0

orhun.begendi
orhun.begendi

Reputation: 937

You should check this article before trying anything. It's all about the theme difference between win 7 and win 10.

https://arbel.net/2006/11/03/forcing-wpf-to-use-a-specific-windows-theme/

Upvotes: 1

Related Questions