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. Now let me explain in more detail.
I have a Slider with value range from 10 to 100 with Interval ticks of 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 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
<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
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.
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. If not possible because the datagrid is too big i need to stop at 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. 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. onve code finish running i click a button that message box scrollbar visibility and i see them as true.
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. I also know exactly everytime the grid datasource changes.
thank you
Edited Datagrid. Code showed LayoutTransform and not RenderTransform. I copied while i was testing LayoutTransform instead just to see if that was it. Anyhow both work on Zoom but zoom to fit fails
Measure
method to manually determine the best scale factor.Measure
will set theDesiredSize
, which you can use to determine how much scaling is needed to get a scale-to-fit by comparing it to the container's size. Also, for this to work, you may need to use LayoutTransform. Here is info about theMeasure
method. msdn.microsoft.com/en-us/library/… – Jason TylerLayoutTransform
that's for sure now.RenderTransform
does not affect theDataGrid
border butLayoutTransform
does. That link does work in this case as the grid always have undetermined Width unless it surpasses the container. But still that is perfect for 2 other controls i have that are very similar to this problematic control and scaling will be for images. Thank you – FranckDataGrid
. That's a bummer. Glad it worked out in the other cases for ya, though. – Jason Tyler