开发者

ListBox item highlighted or selected confusion

in my ListBox , I have 5 numbers 1 - 5 , SelectedItem is databind in TwoWay Mode to SelectedAmount , an int property which has a default value of 1 , whenever I run the Application I have 1 as value selected and highlighted on my ListBox, thats very good but now whenever I change the value to 2 or any other value , the ListBox shows the new value but it is not highlighted , and the SelectedAmount is still holding the old value , that is obviously bad , I want whenever the user changes the selected value, SelectedAmount to get the new value directly , the user now after he made his selection,had to click again to highlight it. any ideas ?

<ListBox ItemsSource="{Binding SiliconAmounts}" SelectedItem="{Binding SiliconAmount,Mode=TwoWay}" Height="31" HorizontalAlignment="Left" Margin="83,148,0,0" VerticalAlignment="Top" Width="149" IsTabStop="True" TabIndex="4" />

my property databind to selectedItem looks like

public int SiliconAmount
    {
        get
        {
            return _SiliconAmount;
        }
        set
        {
            if (_SiliconAmount != value)
            {
                _SiliconAmount =value;
                OnPropertyChanged("SiliconAmount");
            }
        }
    }

my items property looks like

public ObservableCollection<int> SiliconAmounts
    {
        get { return _SiliconAmounts; }
        set
        {
            if (_SiliconAmounts != value)
            {
                _SiliconAmounts = value;
                OnPropertyChanged("SiliconAmounts");
            }
        }
    }

on my viewModel constructor

Silico开发者_JAVA技巧nAmounts = new ObservableCollection<int>();
        SiliconAmounts.Add(1);
        SiliconAmounts.Add(2);
        SiliconAmounts.Add(3);
        SiliconAmounts.Add(4);
        SiliconAmounts.Add(5);

thanks in advance


After posting and reading the comments, it sounds like the problem is UI styling. I have found that Expression Blend is a helpful tool for writing styles and templates on controls. I tend to like to code direct XAML quite a bit, but Expression has an editor for this and some nice tools for setting up visual states, visual triggers, selecting colors, and more. You can get a trial of Blend here. Another tool a lot of WPF developers use is Kaxaml.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜