[WPF] - 为什么RenderSize在所有这三种情况下都保持不变? [英] [WPF] - Why does the RenderSize stay the same in all three of these cases?

查看:1084
本文介绍了[WPF] - 为什么RenderSize在所有这三种情况下都保持不变?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

< Window x:Class =" TestProject.MainWindow" 
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:local =" clr-namespace:TestProject"
mc:Ignorable =" d"
Title =" MainWindow"高度= QUOT; 450"宽度= QUOT; 800">

<! - 以下代码片段在此处 - >

< / Window>


示例1

< ;网格和GT; 
< Grid x:Name =" myGrid"宽度= QUOT; 200"高度= QUOT; 100"背景= QUOT;绿色">
< Grid.LayoutTransform>
< ScaleTransform ScaleX =" 3"的scaleY = QUOT 1 QUOT;的centerX = QUOT; 0.5" CenterY = QUOT; 0.5">< / ScaleTransform>
< /Grid.LayoutTransform>
< / Grid>
< / Grid>


Actu al:

myGrid.RenderSize

{200,100}

  &NBSP;身高:100左右
  &NBSP; IsEmpty:false

  &NBSP;宽度:200

myGrid.DesiredSize

{600,100}

  &NBSP;身高:100左右
  &NBSP; IsEmpty:false

  &NBSP;宽度:600左右


预期:

myGrid.RenderSize

{200,100}

  &NBSP;身高:100左右
  &NBSP; IsEmpty:false

  &NBSP;宽度:600

myGrid.DesiredSize

{600,100}

  &NBSP;身高:100左右
  &NBSP; IsEmpty:false

  &NBSP;宽度:600



示例2

< Grid> 
< Grid x:Name =" myGrid"宽度= QUOT; 200"高度= QUOT; 100"背景= QUOT;绿色">
< Grid.RenderTransform>
< ScaleTransform ScaleX =" 3"的scaleY = QUOT 1 QUOT;的centerX = QUOT; 0.5" CenterY = QUOT; 0.5">< / ScaleTransform>
< /Grid.RenderTransform>
< / Grid>
< / Grid>


实际:

myGrid.RenderSize

{200,100 }¥b $ b  &NBSP;身高:100左右
  &NBSP; IsEmpty:false

  &NBSP;宽度:200

myGrid.DesiredSize

{200,100}

  &NBSP;身高:100左右
  &NBSP; IsEmpty:false

  &NBSP;宽度:200



预期:

myGrid.RenderSize

{200,100}

  &NBSP;身高:100左右
  &NBSP; IsEmpty:false

  &NBSP;宽度:600

myGrid.DesiredSize

{200,100}

  &NBSP;身高:100左右
  &NBSP; IsEmpty:false

  &NBSP;宽度:200



示例3

< Viewbox Stretch =" ; UniformToFill"> 
< Grid x:Name =" myGrid"宽度= QUOT; 200"高度= QUOT; 100"背景= QUOT;绿色">< /网格和GT;
< / Viewbox>


实际:

myGrid.RenderSize

{200,100 }¥b $ b  &NBSP;身高:100左右
  &NBSP; IsEmpty:false

  &NBSP;宽度:200

myGrid.DesiredSize

{200,100}

  &NBSP;身高:100左右
  &NBSP; IsEmpty:false

  &NBSP;宽度:200



预期:



不确定,如果Viewbox使用 RenderTransform 然后我希望
myGrid.RenderSize.Width
为600而 myGrid.DesiredSize.Width 为200,否则如果Viewbox使用
LayoutTransform 然后我希望 myGrid.RenderSize.Width
myGrid.DesiredSize.Width  到是600.
$


我的预期结果是基于 基于以下布局流程阶段:



1. LayoutTransform

2.测量 - 每个元素的DesiredSize是计算机在这里

3.安排 - 子元素在其父母中的位置确定为
4. RenderTransform

5.渲染 - RenderSize是计算机,元素呈现给屏幕



问题:

- Viewbox是否应用RenderTransform或LayoutTransform?

- RenderTransform如何更改元素以使RenderSize尺寸不会改变?

- 例如1,为什么渲染宽度为200,即使LayoutTransform应用于`myGrid`并且Desired with为600 ?



提前谢谢。

解决方案

Rendertransform在渲染之前发生。


它不会改变渲染的内容。


Rendersize是最终呈现的内容  as。


Viewbox适用于代码并应用计算的  scaletransform。


https://referencesource.microsoft.com/#PresentationFramework/src/Framework/System/windows/Controls/ViewBox.cs


https://blog.scottlogic.com/2008/12/19/layouttransform-vs-rendertransform-whats-the-difference.html


<Window x:Class="TestProject.MainWindow"
        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:local="clr-namespace:TestProject"
        mc:Ignorable="d"
        Title="MainWindow" Height="450" Width="800">

        <!--The following code snippets go here-->

</Window>

Example 1

<Grid>
    <Grid x:Name="myGrid" Width="200" Height="100" Background="Green">
        <Grid.LayoutTransform>
            <ScaleTransform ScaleX="3" ScaleY="1" CenterX=".5" CenterY=".5"></ScaleTransform>
        </Grid.LayoutTransform>
    </Grid>
</Grid>

Actual:
myGrid.RenderSize
{200,100}
    Height: 100
    IsEmpty: false
    Width: 200
myGrid.DesiredSize
{600,100}
    Height: 100
    IsEmpty: false
    Width: 600

Expected:
myGrid.RenderSize
{200,100}
    Height: 100
    IsEmpty: false
    Width: 600
myGrid.DesiredSize
{600,100}
    Height: 100
    IsEmpty: false
    Width: 600

Example 2

<Grid>
    <Grid x:Name="myGrid" Width="200" Height="100" Background="Green">
        <Grid.RenderTransform>
            <ScaleTransform ScaleX="3" ScaleY="1" CenterX=".5" CenterY=".5"></ScaleTransform>
        </Grid.RenderTransform>
    </Grid>
</Grid>

Actual:
myGrid.RenderSize
{200,100}
    Height: 100
    IsEmpty: false
    Width: 200
myGrid.DesiredSize
{200,100}
    Height: 100
    IsEmpty: false
    Width: 200

Expected:
myGrid.RenderSize
{200,100}
    Height: 100
    IsEmpty: false
    Width: 600
myGrid.DesiredSize
{200,100}
    Height: 100
    IsEmpty: false
    Width: 200

Example 3

<Viewbox Stretch="UniformToFill">
    <Grid x:Name="myGrid" Width="200" Height="100" Background="Green"></Grid>
</Viewbox>

Actual:
myGrid.RenderSize
{200,100}
    Height: 100
    IsEmpty: false
    Width: 200
myGrid.DesiredSize
{200,100}
    Height: 100
    IsEmpty: false
    Width: 200

Expected:

Not sure, if Viewbox uses RenderTransform then I would expect myGrid.RenderSize.Width to be 600 and myGrid.DesiredSize.Width to be 200, otherwise if Viewbox uses LayoutTransform then I would expect myGrid.RenderSize.Width and myGrid.DesiredSize.Width to be 600.

I am basing my expected results  based on the following layout process stages:

1. LayoutTransform
2. Measure - DesiredSize of each element is computer here
3. Arrange - Position of child elements within their parents is determined
4. RenderTransform
5. Render - RenderSize is computer here, elements are rendered to the screen

Questions:
- Does Viewbox apply RenderTransform or LayoutTransform?
- How does RenderTransform change the element such that RenderSize dimensions do not change?
- For example 1, why is Rendered Width is 200, even though LayoutTransform is applied to `myGrid` and the Desired with is 600?

Thank you in advance.

解决方案

Rendertransform happens before render.

It doesn't transform what's rendered.

Rendersize is what it ends up rendered  as.

Viewbox works in code and applies a calculated  scaletransform.

https://referencesource.microsoft.com/#PresentationFramework/src/Framework/System/windows/Controls/ViewBox.cs

https://blog.scottlogic.com/2008/12/19/layouttransform-vs-rendertransform-whats-the-difference.html


这篇关于[WPF] - 为什么RenderSize在所有这三种情况下都保持不变?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆