【问题标题】:content not centered in viewbox and incorect mouse coord in viewbox内容不在视图框中居中并且在视图框中鼠标坐标不正确
【发布时间】:2019-11-25 08:38:32
【问题描述】:

您好,我正在尝试将应用程序移植到具有 uno 平台的 android。 我在android中的viewbox有一个奇怪的行为, 以下代码在我为测试创建的 uno 应用程序的 uwp 版本中按预期工作。 - 视图框内容不居中 -鼠标位置不准确

在 MainPage.xaml 中

<Grid Background="#FF583793">
        <Viewbox  Stretch="Uniform" StretchDirection="Both">
            <Canvas x:Name="mainCanvas" Height="800" Width="800" Background="#FFA0ACA5" Margin="50,50,50,50" PointerPressed="UIElement_OnPointerPressed">
                <TextBlock x:Name="tblInfos" Height="64" Canvas.Left="10" Canvas.Top="10" Text="TextBlock" TextWrapping="Wrap" Width="780" FontSize="20" FontWeight="Bold"/>
                <TextBlock x:Name="tblInfos2" Height="64" Canvas.Left="10" Canvas.Top="63" Text="TextBlock" TextWrapping="Wrap" Width="780" FontSize="20" FontWeight="Bold"/>
                <Border x:Name="letter" BorderThickness="1" BorderBrush="Black" Height="200" Canvas.Left="50" Canvas.Top="300" Width="500" Background="#FF8D7E3B" HorizontalAlignment="Stretch"/>
            </Canvas>
        </Viewbox>

    </Grid>

MainPage.xaml.cs

 private void UIElement_OnPointerPressed(object sender, PointerRoutedEventArgs e)
        {
            var posCanvas = e.GetCurrentPoint(mainCanvas).Position;
            var posLetter = e.GetCurrentPoint(letter).Position;
            tblInfos.Text = $"canvas x:{posCanvas.X} y:{posCanvas.Y}";
            tblInfos2.Text = $"letter x:{posLetter.X} y:{posLetter.Y}";

        }

可能是我遗漏了什么,或者可能是一个错误?

【问题讨论】:

    标签: get viewbox uno-platform


    【解决方案1】:

    尺子,

    1. 对齐方式: 我发现 ViewBox 与 Uno 的默认对齐方式是左上角,而它在 UWP 上居中。我为此创建了一个问题:https://github.com/unoplatform/uno/issues/2256 您可以通过指定 HorizontalAlignment 和 VerticalAligment

    2. 来解决此问题
    3. 指针位置:在计算相对于目标控件的位置时,似乎没有考虑缩放。这是I've already fixed on WASM 的东西。我觉得在其他平台上还可以,但显然不是……我还创建了an issue,我现在正在研究它。

    【讨论】:

      【解决方案2】:

      现在应该由this PR 解决。它将很快在“开发”预览包中的 nuget 上可用?

      【讨论】:

      • 应该是评论,而不是答案。虽然它确实暗示了 OP 的问题,但仅由链接组成的答案可能会很快失去其价值
      猜你喜欢
      • 2012-01-08
      • 2021-05-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-11-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-05
      相关资源
      最近更新 更多