Question

I have created User control, added ComboBox in it as View1.

View1:-

<UserControl x:Class="XYZ.Views.ComboBoxView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             mc:Ignorable="d" 
             d:DesignHeight="60" d:DesignWidth="600">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="150" />
            <ColumnDefinition Width="300" />
            <ColumnDefinition Width="200" />
            <ColumnDefinition Width="*" />
        </Grid.ColumnDefinitions>
        <TextBlock Grid.Row="1" Grid.Column="0" HorizontalAlignment="Right" VerticalAlignment="Center" Margin="5" Style="{StaticResource textControlText}" Text="{Binding Label}" />
        <ComboBox Grid.Row="1" Grid.Column="1" Margin="5" SelectedItem="{Binding SelectedItem}"  SelectedValue="{Binding Value}" ItemsSource="{Binding Items}" SelectedValuePath="Value" DisplayMemberPath="Ui" SelectedIndex="{Binding SelectedIndex}" Visibility="{Binding Visible}">
            <ComboBox.ToolTip>
                <ToolTip>
                    <TextBlock Text="{Binding Help}" FlowDirection="LeftToRight" TextWrapping="Wrap" MaxWidth="400"/>
                </ToolTip>
            </ComboBox.ToolTip>
        </ComboBox>
    </Grid>
</UserControl>

and i have corresponding View1Model with SelectedItem, SelectedIndex, ObservableCollection of list items and Visible property.

View1Model:-

class XyZComboBoxViewModel
{

    private ObservableCollection<XyZListItem> _items;

    public ObservableCollection<XyZListItem> Items
    {
        get { return _items; }
        set { _items = value; }
    }

    private XyZListItem _selectedItem;

    public XyZListItem SelectedItem
    {
        get { return _selectedItem; }
        set { 
           some code here          
        }
    }

    private Enum _visible;

   public Enum Visibile
   {
    get{return _visible}
    set{return _visible=value //passing System.Windows.Visibility.Collapsed;}
    }

    private int _selectedIndex;

    public int SelectedIndex
    {
        get { return _selectedIndex; }
        set { _selectedIndex = value; }
    }
  }

I have another View2 and View2Model.

In View2Model I create Two View1model objects(i.e 2 ComboBox's) and bind it to second view View2.

<ItemsControl ItemsSource="{Binding Items}" IsTabStop="False"  />

The Two ComboBox's(List Box User control's) getting displayed in the View2.

Now i want to hide the second ComboBox(with Visibility set to Collapsed) on selecting a item from the first ComboBox.

On Selecting an item from first ComboBox, I iterate over the View1Model objects in View2Model and setting the Second ComboBox Visible property value to Visibility.Collapsed.

The problem is I'm not able to hide the second ComboBox.

Please help me.

Was it helpful?

Solution

you can use the mentioned code.

 private Visibility _comboboxvisibility;

   public Visibility comboboxvisibility
   {
       get { return _comboboxvisibility; }
       set { _comboboxvisibility = value; RaisePropertyChanged("comboboxvisibility"); }
   }

   private XyZListItem _selectedItem;

   public XyZListItem SelectedItem
   {
       get { return _selectedItem; }
       set {
           comboboxvisibility = Visibility.Collapsed;         
    }
   }

OTHER TIPS

    public void UpdateAttributes(ComboBox sender)
    {
        var definitions = _attributeDefinitions.ToList();

        {
            var combobox = cmbAttributeDefinition1;

            if (sender != combobox && combobox.SelectedValue != null)
                definitions.RemoveAll(
                    x => x.AttrID == (imProfileAttributeID)combobox.SelectedValue);
        }

        {
            var combobox = cmbAttributeDefinition2;

            if (sender != combobox && combobox.SelectedValue != null)
                definitions.RemoveAll(
                    x => x.AttrID == (imProfileAttributeID)combobox.SelectedValue);
        }

        {
            var combobox = cmbAttributeDefinition3;

            if (sender != combobox && combobox.SelectedValue != null)
                definitions.RemoveAll(
                    x => x.AttrID == (imProfileAttributeID)combobox.SelectedValue);
        }

        {
            var combobox = cmbAttributeDefinition4;

            if (sender != combobox && combobox.SelectedValue != null)
                definitions.RemoveAll(
                    x => x.AttrID == (imProfileAttributeID)combobox.SelectedValue);
        }


        {
            var combobox = cmbAttributeDefinition5;

            if (sender != combobox && combobox.SelectedValue != null)
                definitions.RemoveAll(
                    x => x.AttrID == (imProfileAttributeID)combobox.SelectedValue);
        }


        sender.DataSource = definitions;
        sender.DisplayMember = "Caption";
        sender.ValueMember = "AttrID";
    }

  private void cmbAttributeDefinition1_DropDown(object sender, EventArgs e)
    {
        UpdateAttributes(sender as ComboBox);
    }

    private void cmbAttributeDefinition5_DropDown(object sender, EventArgs e)
    {
        UpdateAttributes(sender as ComboBox);
    }

    private void cmbAttributeDefinition2_DropDown(object sender, EventArgs e)
    {
        UpdateAttributes(sender as ComboBox);
    }

    private void cmbAttributeDefinition3_DropDown(object sender, EventArgs e)
    {
        UpdateAttributes(sender as ComboBox);
    }

    private void cmbAttributeDefinition4_DropDown(object sender, EventArgs e)
    {
        UpdateAttributes(sender as ComboBox);
    }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top