在 C# 中将 RichTextBox 绑定到滑块控件
我想要在 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;
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;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
下面的代码相当于Xaml的后面
The following code behind is equivalent to the Xaml
您确实设置了变换,但没有设置绑定 - 它将被修复。
你需要使用类似的东西
来真正相同
you did set the transform but not the binding - it will be fixed.
You need to use something like
to really to the same
不确定您是否询问如何在代码中执行绑定,或者如何在代码中设置 ScaleX 和 ScaleY 属性(例如,不进行绑定)。如果是这种情况,您可以这样做:
首先,为
ScaleTransform
命名,例如“myScaleTransform
”:然后,为
ScaleTransform
添加一个事件处理程序a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.primitives.rangebase.valuechanged.aspx" rel="nofollow">mySlider
的ValueChanged
事件。在此处理程序中,更新myScaleTransform
的ScaleX
和ScaleY
属性:希望这会有所帮助。
Not sure if you're asking how to perform the binding in code, or how to set the
ScaleX
andScaleY
properties in the code (e.g., without binding). If this is the case, here's how you'd do it:First, give your
ScaleTransform
a name, e.g. "myScaleTransform
":Then, add an event handler for the
ValueChanged
event ofmySlider
. In this handler, update theScaleX
andScaleY
properties ofmyScaleTransform
:Hope this helps.