2015-02-24 42 views
0

我正在使用WPF(C#)中的應用程序,它將使用網絡攝像頭,但我遇到了與主窗口有關的問題。當我在Windows 7中運行它時,我獲得了期望的外觀,但是當我在Windows 8.1機器上運行它時,它看起來不同。在Windows 8.1和Windows 7 WPF窗口不同

這是所需的外觀(Windows 7)中

enter image description here

這就是它看起來像在Windows 8.1(最大化時,它不會延伸到充滿整個屏幕)

enter image description here

這是我的代碼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> 

這是從攝像頭用戶控制

<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> 

我還發現在Webcam.dll源代碼此事件的XAML。

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 

任何幫助將不勝感激!

+0

我在主窗口中的「cam:Webcam ..」項目旁添加了一個邊框,並且它確實拉伸,所以我認爲它必須是攝像頭用戶控件中不允許拉伸的東西。 – mattc19 2015-02-24 02:57:27

+0

如果沒有_minimal_,_complete_代碼示例,任何人都很難提供具體的建議。例如。一個用純WPF代碼顯示Win7和Win8的區別,而不是使用網絡照相庫或硬件。這就是說,你是否嘗試過在用戶控件上使用'Stretch'屬性? – 2015-02-24 04:43:57

+0

您是否嘗試將其包裝在Viewbox中? – 2015-02-24 08:36:15

回答

1

主網格中的凸輪:網絡攝像頭和堆棧面板控件之間存在空間。 所以你的攝像頭:網絡攝像頭被拉伸(對齊設置不是必需的,這是網格的默認行爲)

我的oppinion是問題是WindowsFormsHost或面板。 我更喜歡你用間諜來檢查你的佈局,比如Snoop。 它會幫助你找到你的問題。

+0

感謝您的建議。我發現如果我停止預覽並重新啓動它,它會擴展到全屏(在win 8.1中)。在Win7中,我不必重新啓動。它仍然困擾我,我無法弄清楚,但至少我可以在窗口最大化時重新啓動預覽時發生事件觸發。 – mattc19 2015-02-25 01:59:11

+0

我編輯了原始問題以顯示大小更改時觸發的事件。此事件來自我用於網絡攝像頭控件的dll的源代碼 – mattc19 2015-02-25 02:17:08

相關問題