wpf DEVEXPRESS MVVM:管理 DocumentGroup 中的选项卡
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25850697/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
DEVEXPRESS MVVM: managing tabs in a DocumentGroup
提问by Piero Alberto
I'm working with the MVVM pattern, with C# in VS2013.
我正在使用 MVVM 模式,在 VS2013 中使用 C#。
I have a DocumentGroup in my project and a group of user control (xaml files) in a directory of my project.
我的项目中有一个 DocumentGroup,我的项目目录中有一组用户控件(xaml 文件)。
<dxd:DocumentGroup Name="documentcontainer" ItemHeight="3*" SelectedTabIndex="0" ItemsSource="{Binding tabsCollection}" AllowMove="False" AllowFloat="False" AllowDrag="False">
</dxd:DocumentGroup>
Im my viewModel there is the define of tabsCollection:
我的 viewModel 有 tabsCollection 的定义:
private ObservableCollection<DocumentPanel> p_tabsCollection;
public ObservableCollection<DocumentPanel> tabsCollection
{
get { return p_tabsCollection; }
set
{
p_tabsCollection = value;
base.RaisePropertyChangedEvent("tabsCollection");
}
}
private void Initialize() {
DocumentPanel t = new DocumentPanel( );
t.Content = Application.LoadComponent(new Uri("View/UC/ucImpianti.xaml", UriKind.Relative)); ;
p_tabsCollection.Add(t);
}
- is the type of tabsCollection correct?
- how can I insert my user control (xaml file) in the documentPanel? (if the type is correct)
- tabsCollection 的类型是否正确?
- 如何在 documentPanel 中插入我的用户控件(xaml 文件)?(如果类型正确)
I want create some tabs populated with the user control. From my menu, different voices must open different "usercontrol in tabs", so at the start-time there is no tabs: they are created at runtime, when user clicks on the menu.
我想创建一些填充了用户控件的选项卡。从我的菜单中,不同的声音必须打开不同的“标签中的用户控件”,因此在开始时没有标签:它们是在运行时创建的,当用户单击菜单时。
UPDATED CODE: now it seems correct, but it generates an error/exception when starts..
更新的代码:现在看起来是正确的,但它在启动时会产生一个错误/异常..
UPDATE-->SOLUTION
更新-->解决方案
In this way it works:
它以这种方式工作:
<dxd:DocumentGroup Name="documentcontainer" ItemHeight="3*" ItemsSource="{Binding tabsCollection}" AllowDrag="False" AllowMove="False" AllowSplitters="False" AllowSizing="False" AllowFloat="False" ClosingBehavior="ImmediatelyRemove" SelectedTabIndex="{Binding SelectedDocumentIndex}" >
<dxd:DocumentGroup.ItemStyle>
<Style TargetType="dxd:DocumentPanel">
<Setter Property="CloseCommand" Value="{Binding CloseCommand}" />
</Style>
</dxd:DocumentGroup.ItemStyle>
</dxd:DocumentGroup>
While CloseCommand is the same I posted when I asked this question. The key-to-solution was in the xaml.
虽然 CloseCommand 与我在问这个问题时发布的相同。解决方案的关键在 xaml 中。
回答by Paul O
You can bind your data-collection to the DockLayoutManager.ItemsSourceproperty as shown in the MVVM Support - Building Dock UIhelp article. To visualize elements of the ItemsSource collection as layout items, provide templates via the ItemTemplateor ItemTemplateSelectorproperty.
您可以将数据收集绑定到DockLayoutManager.ItemsSource属性,如MVVM 支持 - 构建 Dock UI帮助文章中所示。要将 ItemsSource 集合的元素可视化为布局项,请通过ItemTemplate或ItemTemplateSelector属性提供模板。
回答by DmitryG
Please, read the following article that described how to use the DevExpress MVVM Framework and the TabbedDocumentUIService implementation that provides methods to create and show documents as tabs: DevExpress MVVM Framework. Interaction of ViewModels. IDocumentManagerService.
请阅读以下文章,该文章描述了如何使用 DevExpress MVVM 框架和 TabbedDocumentUIService 实现,该实现提供了创建和将文档显示为选项卡的方法: DevExpress MVVM 框架。ViewModel 的交互。IDocumentManagerService。
Below is the main idea:
下面是主要思想:
<Button Content="Show Document"
Command="{Binding ShowDocumentCommand}" CommandParameter="Document1" />
...
<dxdo:DockLayoutManager>
<dxdo:LayoutGroup Orientation="Vertical">
<dxdo:DocumentGroup Caption="Documents">
<dxmvvm:Interaction.Behaviors>
<dxdo:TabbedDocumentUIService />
</dxmvvm:Interaction.Behaviors>
</dxdo:DocumentGroup>
</dxdo:LayoutGroup>
</dxdo:DockLayoutManager>
[POCOViewModel]
public class MainViewModel : ViewModelBase {
[ServiceProperty]
protected virtual IDocumentManagerService DocumentManager {
get { return null; }
}
[Command]
public void ShowDocument(string document) {
IDocument doc = DocumentManager.CreateDocument(document, null, this);
doc.Title = document;
doc.Show();
}
}
The complete code example is available in the DevExpress Code Examples database at http://www.devexpress.com/example=E4861.
完整的代码示例可在位于http://www.devexpress.com/example=E4861的 DevExpress 代码示例数据库中找到。
Related step-by-step tutorial series about the building a fully-functional and well-organized MVVM application in a few clicks: Scaffolding Wizards - Getting Started
有关只需单击几下即可构建功能齐全且组织良好的 MVVM 应用程序的相关分步教程系列:Scaffolding Wizards - Getting Started

