WPF控件仅限于父网格的边界 [英] WPF Control limited to bounds of parent grid

查看:73
本文介绍了WPF控件仅限于父网格的边界的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不太确定该怎么问,但是我想创建一个自定义控件,基本上像facebook工具栏聊天一样.我碰到的问题是控件有2个部分,底部显示一个用户名,当您单击时,我希望我的聊天部分最大化,就像facebook和google talks一样.我遇到的主要问题是控件仅限于网格大小,我如何才能使自定义控件的顶部弹出到网格上方.在此先感谢您提供任何见解.

I''m not quite sure how to ask this but I want to create a custom control basically like the facebook toolbar chat. The problem im running into is the control has 2 parts the bottom part which displays a name of a user and when you click that I want my chat part to maximize up just as facebook and google talks does. The main problem I''m having with this is the control is limited to the grid size how can i make the top part of the custom control pop out above the grid. Thanks in advance for any insight

推荐答案

我的想法是:创建两个单独的控件,它们代表松散耦合在一起的两个部分.一个控件应使用另一个控件的接口.这样,您可以与控件功能分开解决布局问题.

让我们考虑顶部"部分使用按钮"部分的界面(您可以翻转它;我不知道您的功能:
One my idea is: create two separate controls representing two parts loosely coupled together. One control should use an interface of another control. In this way, you solve your layout problem separately from controls functionality.

Let''s consider Top part uses interface of Button part (you can flip it; I don''t know your functionality:
public interface IBottomControl { /*..*/ }

public class BottomControl : IBottomControl { /*..*/ }

public class TopControl {
   public IBottomControl BottomControl { get; set; }
   //...
} //class TopControl

//...
//...

TopControl MyTopControl = new TopControl();
BottomControl MyBottomControl = new BottomControl();

//...

MyTopControl.BottomControl = MyBottomControl;



它可以适合您的控制功能吗? (您没有共享任何信息,所以我无法确切知道.)

了解松散耦合很重要.阅读 http://en.wikipedia.org/wiki/Loose_coupling [ http://msdn.microsoft.com/en-us/library/system. windows.controls.dockpanel.aspx [ ^ ],
http://www.wpftutorial.net/DockPanel.html [



Can it fit your control functionality? (You did not share any information on it, so I cannot know exactly.)

It''s important to understand loose coupling. Read http://en.wikipedia.org/wiki/Loose_coupling[^].

Here is another idea:

I found that layout problems are solved much better when you don''t use Grid but use DockPanel instead. See:
http://msdn.microsoft.com/en-us/library/system.windows.controls.dockpanel.aspx[^],
http://www.wpftutorial.net/DockPanel.html[^].

—SA


这篇关于WPF控件仅限于父网格的边界的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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