Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

WPF Combobox: Populating a Combobox with Numbers 1-8

$
0
0

I have a combox box in WPF. I want the combobox values to be the numbers 1-8. I want the selected value at startup to be 2. The code below gives me a blank combobox, with the following error:

"Cannot find resource named 'GeneralLineWidthRange'. Resource names are case sensitive."

Why can't the xaml find the GeneralLineWidthRange property in the code-behind?

XAML:

<ComboBox
   ItemsSource="{Binding Source={StaticResource GeneralLineWidthRange}}"
   SelectedItem="CurrentLineWidth">
</ComboBox>

Code-Behind:

public partial class PreferencesTabGeneral : UserControl
{
    IList<int> generalLineWidthRange = new List<int>();
    int currentLineWidth = 2;

    public PreferencesTabGeneral()
    {
        InitializeComponent();

        for (int i = 1; i < 9; i++)
            generalLineWidthRange.Add(i);

        DataContext = this;
    }

    public IList<int> GeneralLineWidthRange
    {
        get
        {
            return generalLineWidthRange;
        }
        set
        {
            generalLineWidthRange = value;
        }
    }

    public int CurrentLineWidth
    {
        get
        {
            return currentLineWidth;
        }
        set
        {
            currentLineWidth = value;
        }
    }
}





Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>