wpf Caliburn 微型和 tabcontrol

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13214705/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 06:04:18  来源:igfitidea点击:

Caliburn micro and tabcontrol

wpfmvvmcaliburn.micro

提问by GorillaApe

I have looked at most resources but i can find a good solution. I have a tab control HARD coded.

我查看了大多数资源,但我可以找到一个很好的解决方案。我有一个硬编码的选项卡控件。

<TabControl TabStripPlacement="Left" Padding="0" Style="{DynamicResource SettingsTab}" ItemContainerStyle="{DynamicResource SettingsTabItemStyle}" Background="WhiteSmoke" >
                <TabItem Header="ΓΕΝΙΚΑ" Margin="0" IsEnabled="False" > <Grid /></TabItem>                              
                <TabItem Header="Προσωπικ?" Margin="0" IsSelected="True">
                    <Grid MinHeight="400">                     

                        <ContentControl HorizontalAlignment="Stretch" Margin="50,67,50,0"  Name="ActiveItem" />
                    </Grid>
                </TabItem>
                <TabItem Header="Τραπ?ζια" Margin="0">
                    <Grid />
                </TabItem>

UPDATE - Restate problem
Here is my customized tab control. The gray text is a disabled tab item it acts like a group. Like General settings, System settings etc. So it has a role as a navigation menu. Curently i have a content control at each tabitem (not the disabled ones) and bind the view model i want.
But i cant use Conductor.Collection.OneActive with CM.
Why?
I have seen helloscreens example from CM sample and other samples but the problem here is that if i do this via binding then there is no way to display the disabled tabitems other than creating a dummy view model that serves no purpose.So how can i achieve this ?

更新 - 重述问题
这是我自定义的选项卡控件。灰色文本是一个禁用的选项卡项目,它的作用类似于一个组。像一般设置,系统设置等。所以它有一个导航菜单的作用。目前,我在每个 tabitem(不是禁用的)上都有一个内容控件并绑定我想要的视图模型。
但我不能将 Conductor.Collection.OneActive 与 CM 一起使用。
为什么?
我已经从 CM 示例和其他示例中看到了 helloscreens 示例,但这里的问题是,如果我通过绑定来执行此操作,那么除了创建一个无用的虚拟视图模型之外,无法显示禁用的 tabitems。那么我该如何实现这个 ?

ad

广告

采纳答案by Derek Beattie

Update: source here

更新:来源在这里

I have a tab control HARD coded.

我有一个硬编码的选项卡控件。

Is this a requirement?

这是要求吗?

But i cant use Conductor.Collection.OneActive with CM. Why?

但我不能将 Conductor.Collection.OneActive 与 CM 一起使用。为什么?

I think the reason this won't work is to use Conductor.Collection.OneActiveyou need to bind the ItemsSourceto the Items collection. If you're going to bind ItemsSourceyou can't also describe the tab items in XAML.

我认为这不起作用的原因是使用Conductor.Collection.OneActive您需要将 绑定ItemsSource到 Items 集合。如果您要绑定ItemsSource,则不能同时描述XAML.

I created a solution that doesn't involve describing the tab items in xaml.

我创建了一个不涉及在 xaml 中描述选项卡项的解决方案。

The key parts:

关键部分:

In ShellViewthe TabControlItemContainerStyleis described to the tab items IsEnabledproperty can be bound to the view model.

ShellViewTabControlItemContainerStyle被描述为的标签的物品IsEnabled属性可以被绑定到视图模型。

 <TabControl x:Name="Items"
                    Grid.Row="1"
                    TabStripPlacement="Left">
            <TabControl.ItemContainerStyle>
                <Style TargetType="{x:Type TabItem}">
                    <Setter Property="IsEnabled" Value="{Binding IsEnabled}"/>
                </Style>
            </TabControl.ItemContainerStyle>
        </TabControl>

ShellViewModel is similar but we're now activating the second view model because the first one is not enabled.

ShellViewModel 类似,但我们现在激活第二个视图模型,因为第一个未启用。

public class HeaderViewModel : BaseTabViewModel
    {
        public HeaderViewModel(string name)
        {
            DisplayName = name;
            IsEnabled = false;
        }
    }

  public ShellViewModel(Tab2ViewModel tab2ViewModel,
                              Tab3ViewModel tab3ViewModel
            )
        {
             Items.Add (new HeaderViewModel ("ΓΕΝΙΚΑ"));
            Items.Add(tab2ViewModel);
            Items.Add(tab3ViewModel);

            ActivateItem (tab2ViewModel);
        }

Enable or disable the tab item in the constructor of the view model.

在视图模型的构造函数中启用或禁用选项卡项。

 public Tab2ViewModel()
        {
            DisplayName = "Προσωπικ?";
            IsEnabled = true;
        }

The un-styled result is that the first tab item is disabled and the next two are enabled.

未设置样式的结果是第一个选项卡项被禁用,而接下来的两个项被启用。

enter image description here

在此处输入图片说明