简体   繁体   English

将用户控件绑定到滚动条WPF

[英]Bind Usercontrol to scrollbar wpf

I'm having a UserControl which I'm going to use as a Find/Replace UserControl, like the one in Visual studio. 我有一个UserControl ,它将像Visual Studio中的那样用作查找/替换UserControl。

I'm placing this UserControl on top of a TextBox . 我将此UserControl放在TextBox顶部。

Users are able to zoom in and out in the TextBox , which makes the ScrollBar and text smaller/bigger. 用户可以在TextBox放大和缩小,这使ScrollBar和文本变小/变大。

So my question: Is it possible to bind my UserControl to the ScrollBar's width? 所以我的问题是:是否可以将我的UserControl绑定到ScrollBar的宽度?

(I could of course listen to the zoom event and calculate the width, but I would like an easier and better approach) (我当然可以监听缩放事件并计算宽度,但是我想使用一种更简单,更好的方法)

也许是这样的吗?

<UserControl Name="uc" Width="{Binding ElementName=scrollBar, Path=ActualWidth}" />

I solved this by: Comparing TextEditor.TextArea.ActualWidth to TextEditor.ActualWidth , every time the ScrollBar became visible and when the user zoomed. 我解决了这个由:比较TextEditor.TextArea.ActualWidthTextEditor.ActualWidth ,每次时间ScrollBar变得可见,并且当用户放大。 The difference was used to updated the margin of my UserControl . 差异用于更新UserControl的边距。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM