在列表框中的Combobox本身位于TabItem中

时间:2014-03-16 17:08:59

标签: c# wpf combobox listbox tabcontrol

我遇到了这种情况,即使是我最好的朋友“谷歌”也没有帮助。 我有九个TabItems。我能够显示数据。这是我的屏幕。

enter image description here 这是我的方法:

<UserControl.Resources>
    <DataTemplate x:Key="ListItem">
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="450" />
                <ColumnDefinition Width="*" />
            </Grid.ColumnDefinitions>
            <StackPanel Orientation="Horizontal">
                <TextBlock Width="250" Text="{Binding Path=HmiText}" HorizontalAlignment="Right" Height="28" Margin="10,10,0,0" FontSize="12" FontFamily="Calibri" FontWeight="Bold" VerticalAlignment="Center"></TextBlock>
                <ComboBox Width="115" ItemsSource="{Binding ComboBoxSourceItem}" DisplayMemberPath="OptionsText"
                            SelectedValuePath="OptionsValue" SelectedValue="{Binding DefaultValue}" Height="23" Margin="10,5,0,5" HorizontalAlignment="Left"/>
            </StackPanel>
        </Grid>
    </DataTemplate>
</UserControl.Resources>
<TabControl  Grid.Row="1" Grid.ColumnSpan="2" TabStripPlacement="Top"  VerticalContentAlignment="Stretch" BorderThickness="1" BorderBrush="#005399" Background="White">
    <TabItem Header="Unit Configuration" Width="auto">
        <ListBox Name="UnitConfigurationlist" Margin="5" HorizontalContentAlignment="Stretch" ItemsSource="{Binding UnitConfigurationItemSource}" ItemTemplate="{StaticResource ListItem}" >
        </ListBox>
    </TabItem>
    <TabItem Header="Programmable Features" Selector.IsSelected="True" Width="auto">
        <ListBox Name="list" Margin="5" HorizontalContentAlignment="Stretch" ItemsSource="{Binding SelectedProgrammableFeature}" ItemTemplate="{StaticResource ListItem}" >
        </ListBox>
    </TabItem>
    <TabItem Header="Main Menu Configuration" Width="auto" >
        <ListBox Name="MainMenuConfigurationlist" Margin="5" HorizontalContentAlignment="Stretch" ItemsSource="{Binding MainMenuConfigurationItemSource}" ItemTemplate="{StaticResource ListItem}" >
        </ListBox>
    </TabItem>
    <TabItem Header="Cycle Sentry Setup" Width="auto">
        <ListBox Name="CycleSentrySetuplist" Margin="5" HorizontalContentAlignment="Stretch" ItemsSource="{Binding CycleSentrySetuplistItemSource}" ItemTemplate="{StaticResource ListItem}" >
        </ListBox>
    </TabItem>
    <TabItem Header="Language Setup" Width="auto">
    </TabItem>
</TabControl>

这是我的观点模型:

public class UnitConfigurationViewModel : ViewModelBase2
{
    private IOptiSetPlusService optiSetPlusService;

    public ObservableCollection<ProgrammableFeatures> ProgrammableFeaturesItemSource
    {
        get;
        private set;
    }

    public ObservableCollection<ProgrammableFeatures> UnitConfigurationItemSource
    {
        get;
        private set;
    }

    public UnitConfigurationViewModel(IOptiSetPlusService os)
    {
        optiSetPlusService = os;
        InitializeUnitConfiguration();
    }

    void InitializeUnitConfiguration()
    {
        GetControlDependencyID();
        //here I am reading the xml file and filling the collection.
        this.ProgrammableFeaturesItemSource = GetCurrentProgrammableFeaturesItemSource(optiSetPlusService.GetProgrammableFeaturesList(ControlDependency.ControlDependencyId.ToString(), "programmableFeatures"));
        this.UnitConfigurationItemSource = GetCurrentProgrammableFeaturesItemSource(optiSetPlusService.GetProgrammableFeaturesList(ControlDependency.ControlDependencyId.ToString(), "unitConfiguration"));
    }
}

最后这是我的模特:

public class ProgrammableFeatures
{
    string toolTip;
    public string ToolTip
    {
        get
        {
            return toolTip;
        }
        set
        {
            toolTip = value;
        }
    }
    string hmiText;
    public string HmiText
    {
        get
        {
            return hmiText;
        }
        set
        {
            hmiText = value;
        }
    }

    string defaultValue;
    public string DefaultValue
    {
        get
        {
            return defaultValue;
        }
        set
        {
            defaultValue = value;
        }
    }

//this collection will be shown in combobox.
    ObservableCollection<GdtAvailableOptions> comboBoxSourceItem;
    public ObservableCollection<GdtAvailableOptions> ComboBoxSourceItem
    {
        get
        {
            return comboBoxSourceItem;
        }
        set
        {
            comboBoxSourceItem = value;
        }
    }
}

public class GdtAvailableOptions
{
    private string optionsValue;
    public string OptionsValue
    {
        get
        {
            return optionsValue;
        }
        set
        {
            optionsValue = value;
        }
    }

    private string optionsText;
    public string OptionsText
    {
        get
        {
            return optionsText;
        }
        set
        {
            optionsText = value;
        }
    }
}

现在我的问题是一旦组合框选择改变了,它应该影响所有选项卡中的一些其他参数(例如:应该启用rail选项)。我不知道怎么做。请指导我。即使提供的任何链接也会有所帮助。

1 个答案:

答案 0 :(得分:0)

<ComboBox Width="115" ItemsSource="{Binding ComboBoxSourceItem}" DisplayMemberPath="OptionsText"
                            SelectedValuePath="OptionsValue" SelectedValue="{Binding DefaultValue}" Height="23" Margin="10,5,0,5" HorizontalAlignment="Left"/>

您应该在UnitConfigurationViewModel中拥有DefaultValue的公共属性 当它被改变时你应该打电话给集合
在集合中操纵你需要的东西

您可能遇到多个集合共享的一个属性的问题 并看看开发hedgehog的评论