Bind SelectedValue for compiling WPF

I tried searching up and down for this, but can't find anything. I have combobox on the list. Listview is bound to a list of objects opened through the controller to which the datacontext is bound. One of the properties of items in a list is a string. I am trying to associate this value with what is in combobox.

Here is a snippet of my list

<ListView ItemsSource="{Binding Path=OrderLines}" >

            <ListView.View>
                <GridView>
                    <GridViewColumn Header="Item Type" Width="Auto">
                        <GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <ComboBox Width="100" SelectedItem="{Binding Path=LineType,ValidatesOnDataErrors=True}" >

                                    <ComboBoxItem>Type1</ComboBoxItem>
                                    <ComboBoxItem>Type2</ComboBoxItem>
                                    <ComboBoxItem>Type3</ComboBoxItem>
                                    <ComboBoxItem>Type4</ComboBoxItem>
                                </ComboBox>
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>    
                </GridView>
             </ListView.View>

In the controller, I have an OrderLines property similar to this

    private List<OrderLine> orderLines;
    public List<OrderLine> OrderLines 
    { 
        get { return orderLines; }
        set
        {
            if (value == orderLines)
                return;

            orderLines= value;

            OnPropertyChanged("OrderLines");
        }
    }

And OrderLine just has the LineType property, which is a string containing a value.

    private string lineType;
    public string LineType 
    {
        get { return lineType; }

        set
        {
            lineType= value;
            OnPropertyChanged("LineType ");
        }
    }

Can someone explain why the selected item / value is not set. Is this because my content is hard-coded? Thank you for your help.

+3
source share
1

, , , LineType - , ComboBox ComboBoxItems != ComboBoxItem.

-

 <ComboBox>
      <system:String>Item1</system:String>
      <system:String>Item2</system:String>
 </ComboBox>

- , mscorlib

+4

Source: https://habr.com/ru/post/1734298/


All Articles