防止CaptureElement尝试拍摄图像大小并推出scrollviewer

时间:2017-05-12 11:45:15

标签: graphics uwp

我有一个容器层次结构,其中包括一个向上的滚动查看器,所以我可以看到我的整个表单。在内部,我可以使用CaptureElement,它在启动时以640 * 480的分辨率连接到网络摄像头。

我看到的,我不想要而且似乎无法阻止的行为是,捕获元素尝试采用与图像分辨率640 * 480相同的渲染大小,即使它被设置为拉伸也是如此。因此,它将使用scrollviewer将所有容器推出到一个容器。我希望它的行为与其他控件一样,比如Button等,它只占用可用的内部大小,而滚动查看器只有在必要时才会参与。

以下代码都证明了这一点,但是注释/取消注释以查看按钮而不是CaptureElement:

Inherits Page

Private mc As New MediaCapture
Private ce As New CaptureElement

Private WithEvents TopGrid As New Grid
Private vs As New ScrollViewer
Private WithEvents CamGrid As New Grid

Private but As New Button

Public Sub New()

    ' This call is required by the designer.
    InitializeComponent()

    ' Add any initialization after the InitializeComponent() call.

    Content = TopGrid

    TopGrid.Width = 600
    TopGrid.Height = 200
    TopGrid.Children.Add(vs)
    vs.Content = CamGrid
    vs.HorizontalScrollBarVisibility = ScrollBarVisibility.Visible
    vs.VerticalScrollBarVisibility = ScrollBarVisibility.Visible

    but.Content = "hello"

    but.HorizontalAlignment = HorizontalAlignment.Stretch
    but.VerticalAlignment = VerticalAlignment.Stretch
    ce.HorizontalAlignment = HorizontalAlignment.Stretch
    but.VerticalAlignment = VerticalAlignment.Stretch

    InitCam()


    CamGrid.Children.Add(ce)
    'CamGrid.Children.Add(but)

End Sub

Private Async Sub InitCam()
    Await mc.InitializeAsync
    ce.Source = mc
    Dim t = mc.StartPreviewAsync
End Sub

Private Sub CamGrid_SizeChanged(sender As Object, e As SizeChangedEventArgs) Handles CamGrid.SizeChanged
    Dim w = e.NewSize.Width
    Dim h = e.NewSize.Height
    Dim a = 1
End Sub

1 个答案:

答案 0 :(得分:0)

好的,我找到了答案。在更高级别的滚动查看器中,使用画布来控制要管理大小的控件。 Canvas不会扩展以包含它的子节点,因此不会导致冲突/递归。