将RichTextBox绑定到C#中的Slider控件
作者:互联网
我有以下要在xaml.cs中执行的XAML代码.
<RichTextBox.LayoutTransform>
<ScaleTransform ScaleX="{Binding ElementName=mySlider, Path=Value}"
ScaleY="{Binding ElementName=mySlider, Path=Value}"/>
</RichTextBox.LayoutTransform>
基本上它将滑块绑定到richtextbox并执行缩放.
以下是我的尝试:
RichTextBox newtext = new RichTextBox();
ScaleTransform mytran = new ScaleTransform();
mytran.ScaleX = mySlider.Value;
mytran.ScaleY = mySlider.Value;
newtext.LayoutTransform = mytran;
解决方法:
后面的代码相当于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;
标签:c,wpf,xaml,binding,scaletransform 来源: https://codeday.me/bug/20190521/1147811.html