如何在WPF中设置滚动条 [英] how to set an scrollbar in wpf

查看:135
本文介绍了如何在WPF中设置滚动条的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

hi
我正面临在需要时获取滚动条的问题(控件溢出).我正在wpf中动态创建控件,iam使用控件平移作为画布.我让滚动条达到极限,而我的控件超出极限,
我曾在xaml中尝试过此代码,
我要去哪里了,请引起您的注意
谢谢q


hi
i am facing the problem with getting the scroll bar when it is needed (controls are over flowed).i am creating the controls dynamically in wpf, iam using the controls pan as canvas. iam getting the scroll bar upto limit and my controls are coming out of the limit,
i had tried with this code in xaml,
where i am going wrong , please set your attention for this
thank q


<ScrollViewer Height="149" Width="854" Canvas.Left="44" ><canvas></canvas></ScrollViewer>



尝试此操作后,我也将控件从画布上删除了,请给我个主意
非常感谢您的关注



after trying this also iam getting the controls out of the canvas , please give me the idea
thanks a lot for your attention

推荐答案

您好sivakumarmr10,

您发布的代码包含一个小错误,因为Canvas控件应以大写字母"C"开头.除此之外,基本想法似乎还不错.

以下代码段应在Visual Studio中呈现:



Hi sivakumarmr10,

The code you posted contained a small error in that the Canvas control should begin with a capital ''C''. Other then that the basic idea seemed fine.

The following code snippet should render in Visual Studio :



<Window

xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

Title="Window1" Height="300" Width="300">
<ScrollViewer>
    <Canvas Width="10" Height="10">
        <Button Height="15" Width="15" Background="Red"/>
    </Canvas>
</ScrollViewer>
</Window>




至于动态添加控件,您可能会发现WrapPanel更适合您的需求.根据您使用的控件类型,我可能会建议您发现一种更有用的方法,但我需要更多信息.

我不确定这是否是您的意图,但您可能还想避免明确定义控件的Width和Height以及Canvas位置,因为这可能会导致可伸缩性问题.

微软提供了一个很棒的工具来快速解析和呈现XAML,可以在这里找到:

XAML Pad




As for dynamically adding controls, you might find that a WrapPanel would suit your needs better. Depending on the type of Controls that you use I could suggest a method you might find more helpful, but I would need more information.

I''m not sure if it was your intention but you may also want to avoid explicitly defining the Width and Height of the controls as well as the Canvas position, as this may cause scalability issues.

A great tool made by Microsoft to quickly parse and render XAML can be found here :

XAML Pad


这篇关于如何在WPF中设置滚动条的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆