如何使用WPF使窗口滑出(表达式Blend 4和C#)
我试图弄清楚如何连接窗口,以便使用主窗口左侧或右侧的小按钮滑出。我想做的是创建一个主窗体,并连接两个窗口。对于其中一个窗口,当用户按下主窗口上的按钮时,它会使窗口看起来滑出而不是弹出。这是我的想法 http://www.youtube.com/watch? v=CVlSj0yr3rg&feature=lated ..然后,用户更改值,主窗口将更新为新信息。老实说,我已经完成了所有代码的编写,并在 Visual Studio 2010 的 Windows 窗体(带有弹出窗口)中使所有内容都正常工作。但我认为制作一个更具吸引力的 GUI WPF 是可行的方法,而且我喜欢学习它。如果您有任何论坛、教程或一般答案,那就太好了。
I am trying to figure out how to connect windows so the slide out using a small button from the left or right of a main window. What I am trying to do is create a main form with 2 windows connected to it. For one of the windows when the user presses a button on the main window it makes the window seem to slide out rather than pop up. Here is where I got the idea http://www.youtube.com/watch?v=CVlSj0yr3rg&feature=related ..The user then changes a value and the main windows is updated with new information. Honestly I have finished writing all my code and got everything working in Windows Forms in visual studio 2010 (with pop up windows).But I am thinking to make a more appealing gui WPF is the way to go, plus I like learning about it. If you have any forums, tutorials or general answers that would be great.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好的,从视频来看,您确实需要某种可以打开的扩展器,而不是窗口。窗口是一个有边框的区域,标准按钮和标题栏位于顶部。
这可以通过具有两列的网格来完成。一种设置为自动宽度,一种设置为*宽度。在自动调整大小的一个中,您可以放置扩展的内容,而在另一个中则可以放置始终可见的内容。
执行此操作的简单方法:
Xaml
代码隐藏
这绝不是完整的方法,也不是最好的方法。但它是最容易实现的之一。更好的方法是使用 ViewModel 来处理扩展区域的状态,以及一些动画以使其平滑过渡。如果您想要该视频中完成的滑动行为,则可以使用动画。如果您使用 Blend,那么您就有了正确的动画工具。
就我个人而言,我希望这个 Windows ViewModel 有一个属性(我们称其为 Boolean 形式的 DrawerExpanded),自定义 Expander 将其 IsExpanded 属性绑定到该属性。然后,我将创建一个打开动画,用于设置扩展器中内容的宽度,以及一个将宽度设置为 0 的关闭动画。此外,在每个动画中,我可能会设置可见性和不透明度,以使效果更好,不奇怪。假设展开动画在 0.5 秒时将宽度设置为 350,在 0.5 秒时将可见性设置为可见,然后在 0.5 秒到 0.7 秒之间将不透明度从 0 设置为 100。这样抽屉就会滑出,内容很快就会消失在视野中。
如果您想要一个代码示例,您可能需要给我几分钟时间。
OK, so judging from the video you really want some kind of expander that opens and not a Window. A Window is an area with border, and the standard buttons and titlebar at the top.
This can be done with a grid with two columns. One is set to Auto width, one is set to * width. In the Auto sized one you can put your expanding content, and have your always visible content in the other.
The simple way to do this:
The Xaml
The Code-behind
This is by no means the complete way, or the best way. It is one of the simplest to implement though. A better way would be with a ViewModel which would handle the state of the expanded area, along with some animations to make it a smooth transition. If you want the sliding behaviour that is done in that video, animations are where it is at. If you are using Blend, then you have the right tool for animations.
Personally I would have this Windows ViewModel have a property (lets call it DrawerExpanded as Boolean) that a customized Expander would bind its IsExpanded property to. I would then create an open animation that sets the width of the content in the expander, and a close animation that sets the width to 0. Additionally, in each of these I would probably include setting the visibility and opacity to make the effect better and not weird. So lets say expand animation sets Width to 350 at .5 seconds, Visibility to visible at .5 seconds, and then opacity from 0 to 100 from .5 seconds to .7 seconds. That way the drawer slides out and the content fades quickly into view.
If you want a code example of that, you may have to give me a few mins.
我真的会采取简单/友好的方式在 Expression Blend 中创建
视觉状态
。基本上只有“进入状态”和“退出状态”,以及允许控件触发状态更改的InteractionTrigger
。它很棒而且非常用户友好。后面没有代码:) 希望它对您有帮助!
作为奖励,您可以轻松添加过渡效果,就像在幻灯片中一样。 xaml 代码变得相当冗长,但在 Blend 中工作允许您使用 IDE 来管理您以可视方式添加的所有内容。
您甚至可以使用交互触发器在其他控件的可见性状态之间切换,而不是编写转换器等。
I would really just take the easy/friendly route of creating
Visual States
in Expression Blend. There's basically just an "in state" and "out state", and anInteractionTrigger
that allows the control to trigger the state change. Its awesome and extremely user friendly.No code behind :) Hope it helps you!
As a bonus, you can easily add transition effects just like in a powerpoint. The xaml code gets pretty verbose, but working in Blend allows you to use the IDE to manage everything you add visually.
You can even use the
Interaction Trigger
to toggle between visibility states of the other controls, rather than writingconverters
, etc.