简体   繁体   English

WPF RenderTransform比例尺问题

[英]WPF RenderTransform scale questions

I am trying to find answer to my problem without success. 我试图找到解决问题的答案,但没有成功。 didn't found anyone trying to do something similar. 没发现有人试图做类似的事情。

I am simply trying to have a default scale factor on a DataGrid (object doesn't matter) and have it manually editable. 我只是想在DataGrid上使用默认比例因子(对象无关紧要),并使其可手动编辑。 Now let me explain in more detail. 现在让我更详细地解释。

I have a Slider with value range from 10 to 100 with Interval ticks of 10. 我有一个滑块,其值范围从10到100,间隔刻度为10。

<Slider Name="sldZoom" 
        IsSnapToTickEnabled="True" 
        Height="180" 
        Orientation="Vertical" 
        TickPlacement="Both" 
        Minimum="10" 
        Maximum="100" 
        Ticks="10, 20, 30, 40, 50, 60, 70, 80, 90, 100" 
        Value="10" HorizontalAlignment="Center" />

Then i have a ScrollViewer with fix Height and Width for format purpose 然后我有一个固定高度和宽度的ScrollViewer以用于格式化目的

<ScrollViewer Name="scrZoomPanel" 
              HorizontalScrollBarVisibility="Auto" 
              VerticalScrollBarVisibility="Auto" 
              Height="500
              Width="750" 
              Background="White">

And at last I have in the scrollviewer a DataGrid with random columns and row quantity 最后,我在scrollviewer中有一个带有随机列和行数的DataGrid

<DataGrid Name="grdArrangement"
          HorizontalAlignment="Stretch" 
          HorizontalContentAlignment="Stretch" 
          VerticalAlignment="Top" 
          ItemsSource="{Binding Path=ListData}" 
          IsHitTestVisible="False" 
          CanUserAddRows="False" 
          CanUserDeleteRows="False"
          CanUserReorderColumns="False" 
          CanUserSortColumns="False" 
          HeadersVisibility="None" 
          AutoGenerateColumns="True" 
          GridLinesVisibility="None" 
          SelectionMode="Single"       
          AutoGeneratingColumn="grdArrangement_AutoGeneratingColumn"  
          AutoGeneratedColumns="grdArrangement_AutoGeneratedColumns" 
          Background="White" >
          <DataGrid.RenderTransform>
              <ScaleTransform  
                              ScaleX="{Binding ElementName=sldZoom, Path=Value, Converter={StaticResource ZoomRatio}}" 
                              ScaleY="{Binding ElementName=sldZoom, Path=Value, Converter={StaticResource ZoomRatio}}" />
          </DataGrid.RenderTransform>
  </DataGrid>

the 2 auto generate event is because the grid get different cell styles assigned to it eveytime datasource changes 2自动生成事件是因为网格获得了分配给它的不同的单元格样式eveytime数据源更改

So datagrid can get different amount of rows and columns and at Zoom Value 100 the scale is 1. At Zoom value of 10 scale is 0.1. 因此,datagrid可以获取不同数量的行和列,并且在“缩放值” 100处缩放比例为1。在“缩放值” 10处缩放比例为0.1。

In some case the grid get's bigger than the scrollviewer and it shows scrollbar and that's fine but what i want is : after the binding is complete and onpaint completed (everything generated), I want to zoom to the level that allow me to see everything. 在某些情况下,网格变得比scrollviewer大,并且显示滚动条,这很好,但是我想要的是:绑定完成并且onpaint完成(生成的所有内容)之后,我想缩放到允许我看到所有内容的级别。 If not possible because the datagrid is too big i need to stop at Zoom 10 (10%). 如果不可能,因为数据网格太大,我需要停在Zoom 10(10%)。 I need the zoom factor to stop ONLY on ticks that is inside the list. 我需要缩放因子以仅停止列表中的刻度。

I tried iterating over the slide ticks and set the zoom and check if the scrollviewer still display scrollbars but that doesn't work the scrollviewer always show value before everything change. 我尝试遍历幻灯片刻度并设置缩放比例,并检查scrollviewer是否仍显示滚动条,但这不起作用,scrollviewer始终在所有更改之前显示值。 By that i mean if the grid was 1x1 pixel the scroll viewer scroll ba visible was false even if it zommed in enought for the 1x1 grid to be 1000 % zoom so 1000x1000 pixel and scrollbar actually shows. 我的意思是,如果网格为1x1像素,则滚动查看器的可见滚动ba是错误的,即使它放大到足以使1x1网格达到1000%缩放的程度,所以实际上显示的是1000x1000像素和滚动条。 onve code finish running i click a button that message box scrollbar visibility and i see them as true. onve代码完成运行,我单击消息框滚动条可见性的按钮,我将其视为真实。

Seems like changing the slider value doesn't update the scale transform of the grid right away. 似乎更改滑块值不会立即更新网格的比例转换。

So in short i simply want a Scale To Fit and that happen only once every binding update of the datagrid. 简而言之,我只是想要一个Scale to Fit,并且该绑定仅在datagrid的每次绑定更新中发生一次。 I also know exactly everytime the grid datasource changes. 我也确切地知道每次网格数据源发生更改。

thank you 谢谢

Edited Datagrid. 编辑的Datagrid。 Code showed LayoutTransform and not RenderTransform. 代码显示LayoutTransform而不是RenderTransform。 I copied while i was testing LayoutTransform instead just to see if that was it. 我在测试LayoutTransform时复制了它,只是为了看看是否就是那样。 Anyhow both work on Zoom but zoom to fit fails 无论如何,两者都可以在“缩放”上工作,但缩放失败

I started looking at the problem form another angle and try getting 我开始从另一个角度看问题,然后尝试

scrZoomPanel.ComputedHorizontalScrollBarVisibility

and

scrZoomPanel.ComputedHorizontalScrollBarVisibility

to be anything else than original value before altering the DataGrid. 在更改DataGrid之前,除了原始值外,其他任何值都可以。

So i was looking to a way to force refresh of the scrZoomPanel and found ou there is a function for that : 所以我一直在寻找一种强制刷新scrZoomPanel ,发现您有一个用于此的功能:

scrZoomPanel.UpdateLayout();

If i call that every time just before trying to read the scrZoomPanel.ComputedHorizontalScrollBarVisibility then it finally return me the real value. 如果我在尝试读取scrZoomPanel.ComputedHorizontalScrollBarVisibility之前每次都调用它,那么它将最终返回我的真实值。

But i find that a bit invasive needing to call that every single time. 但是我发现有点麻烦,需要每次都打电话。 Wonder if there is a way to make a binding change force refresh in XAML instead of background code. 不知道是否有一种方法可以使XAML中的绑定更改强制刷新,而不是后台代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM