Getting/Returning A Specific Attribute from a Collection using ComboBox in c#/WPF

Viewed 27

How do I get the attribute "longName" returned when I click on a value from the combo box?

When I run the Code I get: enter image description here

But If I click on Anything in the combo box I get the collection returned enter image description here

I am guessing I need more trigger events but I am unsure what ones I need. I looked at a few of the suggested answers and they all seemed to be coded rather than XAML trigger events but I was unable to get them to work (as I am still new to c#).

        <Style TargetType="ComboBoxItem">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate>
                        <StackPanel Orientation="Horizontal" Margin="4" MinHeight="25" Background="{TemplateBinding Background}">
                            <TextBlock Text="{Binding longName}" Margin="4,0,0,0" VerticalAlignment="Center" />
                        </StackPanel>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
            <Setter Property="Background" Value="Transparent"/>
            <Style.Triggers>
                <Trigger Property="IsMouseOver" Value="True">
                    <Setter Property="Background" Value="#1E1E1E" />
                    <Setter Property="Foreground" Value="Pink" />
                </Trigger>
            </Style.Triggers>
        </Style>

    <ComboBox Height="50" Margin="0,20,40,200" ItemsSource="{Binding Path=lineItems}" 
     IsEditable="True" StaysOpenOnEdit="True" Text="{Binding lineItems, UpdateSourceTrigger=PropertyChanged}">
        public class LineItems
        {
            public string variableName { get; set; }
            public string variableUnit { get; set; }
            public bool variableGrowthCheck { get; set; }
            public bool variableAVGCheck { get; set; }
            public bool variableSVCheck { get; set; }
            public string longName { get; set; }
            public int priority { get; set; }
            
        }
0 Answers
Related