WPF可调整大小的Tab控件 [英] WPF resizable Tab control

查看:138
本文介绍了WPF可调整大小的Tab控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

如何在WPF中调整选项卡控件的大小,以使两个选项卡并排显示...类似于在MDI应用程序中调整子窗口的大小以比较它们的内容.

How can I resize Tab control in WPF so that two tabs appear side by side....similar to resizing child windows in an MDI application to compare their contents.

是否可以像WPF中那样调整选项卡控件的大小.如果可以的话,我可以如何做一些指导.

Is it possible to resize tab controls like that in WPF. If so can i have some guidance on how to do that.

谢谢!

 

 

推荐答案

很抱歉让您失望,但是WPF附带的默认TabControl不支持这种功能.我也不会忘记在互联网上的其他地方看到它.

I'm sorry to disappoint you, but a default TabControl, that comes with WPF doesn't support such a functionality. I also don't remeber seeing it somewhere else on the internet.

但是,如果我理解您的观点正确,那么您正在尝试创建并排视图,以便您可以进行比较?
我有一个方法.

However, if I understood you correct, you're trying to create a side by side views so you can compare them?
I have an idea how to do that.

  1. 创建一个ViewModel类(如果您不了解MVVM,请阅读以下文章 http://msdn.microsoft.com/en-us/magazine/dd419663.aspx )
  2. 在ViewModel中,创建2个名为 ListCollectionView 的属性 LeftItems RightItems .
  3. 如果要使两个控件保持同步,请转到4,否则转到6 :)
  4. 在每个集合上都订阅 CurrentChanged 事件,如代码所示以下.
  5. 在CurrentChanged触发时,调用 MoveCurrentToPosition 来更新 CurrentItem 在相反位置的位置.
  6. 在视图上创建2个 TabControls -每个都在一侧.
  7. 将两个TabControl上的 ItemSource 属性绑定到LeftItems/RightItems并进行设置 IsSynchronizedWithCurrentItem = True
  8. 其余所有内容与该链接下的示例相同.
  1. Create a ViewModel class (if you don't know anything about MVVM, please read the following article http://msdn.microsoft.com/en-us/magazine/dd419663.aspx)
  2. In a ViewModel create 2 ListCollectionView properties called LeftItems and RightItems.
  3. If you want to keep both controls sychronized, goto 4 else goto 6 :)
  4. On each of those collections subscribe to CurrentChanged event like shown in code below.
  5. Call MoveCurrentToPosition to update position of CurrentItem in the opposite colleciton when CurrentChanged triggers.
  6. On view create 2 TabControls - each on one side.
  7. Bind ItemSource property on both TabControl to LeftItems/RightItems and set IsSynchronizedWithCurrentItem = True
  8. All the rest is the same as in example under the link.

添加了缺少的代码

public MainWindow()
{
  InitializeComponent();
  DataContext = this;

  LeftItems = new ListCollectionView(new List<string> { "1", "2", "3" });
  RightItems = new ListCollectionView(new List<string> { "4", "5", "6" });

  LeftItems.CurrentChanged += (s, e) => RightItems.MoveCurrentToPosition(LeftItems.CurrentPosition);
  RightItems.CurrentChanged += (s, e) => LeftItems.MoveCurrentToPosition(RightItems.CurrentPosition);
}

public ListCollectionView LeftItems { get; set; }
public ListCollectionView RightItems { get; set; }

< TabControl Grid.Column = " 0" &ItemsSource =" { 绑定   LeftItems } &; = " True"  /> ;
< TabControl &Grid.Column = " 1" &ItemsSource =&; { &RightItems } &; span> = " True"  />

<TabControl Grid.Column="0" ItemsSource="{Binding LeftItems}" IsSynchronizedWithCurrentItem="True" />
<TabControl Grid.Column="1" ItemsSource="{Binding RightItems}" IsSynchronizedWithCurrentItem="True" />

如果您需要其他帮助,请随时提出任何问题.

If you need additional help, feel free to ask any question.


这篇关于WPF可调整大小的Tab控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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