I have the following XAML code that I want to perform in xaml.cs.
<RichTextBox.LayoutTransform>
<ScaleTransform ScaleX="{Binding ElementName=mySlider, Path=Value}"
ScaleY="{Binding ElementName=mySlider, Path=Value}"/>
</RichTextBox.LayoutTransform>
Basically it binds the slider to the richtextbox and performs zooming.
The following is what i have attempted:
RichTextBox newtext = new RichTextBox();
ScaleTransform mytran = new ScaleTransform();
mytran.ScaleX = mySlider.Value;
mytran.ScaleY = mySlider.Value;
newtext.LayoutTransform = mytran;
The following code behind is equivalent to the Xaml
//<RichTextBox.LayoutTransform>
// <ScaleTransform ScaleX="{Binding ElementName=mySlider, Path=Value}"
// ScaleY="{Binding ElementName=mySlider, Path=Value}"/>
//</RichTextBox.LayoutTransform>
ScaleTransform scaleTransform = new ScaleTransform();
Binding scaleXBinding = new Binding("Value");
scaleXBinding.Source = mySlider;
Binding scaleYBinding = new Binding("Value");
scaleYBinding.Source = mySlider;
BindingOperations.SetBinding(scaleTransform,
ScaleTransform.ScaleXProperty,
scaleXBinding);
BindingOperations.SetBinding(scaleTransform,
ScaleTransform.ScaleYProperty,
scaleYBinding);
RichTextBox newText = new RichTextBox();
newText.LayoutTransform = scaleTransform;
you did set the transform but not the binding - it will be fixed. You need to use something like
Binding scaleBinding = new Binding("Value"){ElementName="mySlider"};
BindingOperations.SetBinding(mytran, ScaleTransform.ScaleXProperty, scaleBinding);
BindingOperations.SetBinding(mytran, ScaleTransform.ScaleYProperty, scaleBinding);
to really to the same
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With