mattc19
mattc19

Reputation: 718

WPF window different in windows 8.1 and windows 7

I'm working on an application in WPF (C#) that will use a webcam but I'm having issues with the main window. I am getting my desired look when I run it in windows 7 however when I run it on a windows 8.1 machine it looks different.

This is the desired look (Windows 7)

enter image description here

This is what it looks like on Windows 8.1 (it doesn't stretch to fill the screen when maximizing)

enter image description here

Here is my code for the mainwindow.xaml

<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:cam="clr-namespace:WebcamControl;assembly=WebcamControl"    
Title="WPF Webcam" Height="664.333" Width="645">
<Window.Resources>
    <DataTemplate x:Key="DevicesListTemplate">
        <TextBlock Text="{Binding Name}"/>
    </DataTemplate>
</Window.Resources>


<Grid Margin="0,0,0,0">
    <Grid.RowDefinitions>
        <RowDefinition/>
        <RowDefinition Height="50"/>
    </Grid.RowDefinitions>
    <cam:Webcam Name="WebcamCtrl" Margin="10" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"/>

    <StackPanel Margin="0,0,0,0" Orientation="Horizontal"  Grid.Row="1">
        <ComboBox HorizontalAlignment="Left" Height="23" Width="200" VerticalAlignment="Center"
            x:Name="AudioDevicesComboBox" ItemTemplate="{StaticResource DevicesListTemplate}" Margin="10,0,10,0"/>
        <ComboBox Height="22" Width="200" HorizontalAlignment="Right" VerticalAlignment="Center"
            x:Name="VideoDevicesComboBox" ItemTemplate="{StaticResource DevicesListTemplate}" Margin="0,0,10,0"/>
        <TextBox x:Name="tbScan" HorizontalAlignment="Left" Height="22" Margin="0,0,10,0" TextWrapping="Wrap" VerticalAlignment="Center" Width="100" KeyDown="tbScan_KeyDown"/>
        <Button Content="Start" HorizontalAlignment="Left" Height="22" Margin="0,0,10,0" VerticalAlignment="Center" Width="78" Click="Button_Click_1"/>
    </StackPanel>

</Grid>

This is the xaml from the webcam user control

<UserControl x:Class="Webcam" 
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"              
         xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
         xmlns:wf="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms"
         MinHeight="100" MinWidth="100"
         mc:Ignorable="d">
<Grid>
    <WindowsFormsHost Name="WinFormsHost" Margin="0" Background="{x:Null}">
        <wf:Panel x:Name="WebcamPanel"/>
    </WindowsFormsHost>
</Grid>

I also found this event in the Webcam.dll source code.

    Private Sub Webcam_SizeChanged(sender As Object, e As SizeChangedEventArgs) Handles Me.SizeChanged
    If (deviceSource IsNot Nothing) Then
        deviceSource.PreviewWindow.SetSize(New Size(CInt(Me.ActualWidth), CInt(Me.ActualHeight)))
    End If
End Sub

Any help would be greatly appreciated!

Upvotes: 0

Views: 508

Answers (1)

sac1
sac1

Reputation: 1344

There is space between cam:Webcam and Stackpanel control in Main Grid. So your cam:Webcam is streched (Alignments setups are not necessary, this is the default behavior of Grid)

My oppinion is the problem is WindowsFormsHost or Panel. I prefer to you to check your layout with a spy, like Snoop. It will help for you to find your problem.

Upvotes: 1

Related Questions