WPF Scaling Issue?

I tried the following and I am getting the behavior you are going for (the rectangle is scaled and the grid is sized correctly).

Up vote 0 down vote favorite share g+ share fb share tw.

I am perplexed with an issue that I am experiencing, using ScaleTransform. I have a Grid with a fixed width and height. The grid contains one child, a Rectangle.

The Rectangle's Fill is a VisualBrush whose Visual binds to a canvas outside of the grid, whose dimensions are rather large. On the rectangle, I use a ScaleTransform, with ScaleX and ScaleY both being set to 0.18. Essentially, I am trying to scale the Rectangle's visual down to fit within my grid.

What appears to be happening is that the Grid itself is being scaled down, resulting in a much smaller result than what I want. I have included the code below. Just as a point of reference, the height and width that the rectangle binds do are essentially 900 by 600, respectively.

Any pointers as to what I might be doing wrong would be greatly appreciated. Wpf link|improve this question asked Aug 19 '10 at 17:31Chris415519 37% accept rate.

Unless I am mistaken the ActualHeight and ActualWidth properties as they normally mean in WPF are not DP's and you cannot bind to them. As has been pointed out below these are readonly dependency properties. Assuming this is in a CustomControl style Binding should be changed to TemplateBinding first.

I removed the bindings and essentially created a static version of your XAML which looks just fine. Since you have Part_Content defined for the grid, I am curious, is this xaml part of a custom control style? Is the code of the CustomControl manipulating the grid via PART_Content?

ActualHeight and ActualWidth are readonly DependencyProperties. There's no reason you can't use them as a Binding Source like Chris is doing - Source can be any CLR property. It's only the Target that needs to be a DP.

In this case you can't assign a value to either of them because they're readonly and so can't be used as a Target. – John Bowen Aug 19 '10 at 21:27 "Source can be any CLR property" but for the binding to make sense it needs to be backed by INotifyPropertyChanged. That said I did say that I could be mistaken that these are not DP's.

Quite frankly I find this code to be very very odd. If indeed he wants to bind to ActualHeight and ActualWidth he should be using TemplateBinding and not Binding. You use binding when you want to bind to something in the datacontext and I am pretty certain he doesn't have ActualHeight/Width in his VM.

– NVM Aug 19 '10 at 21:38.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions