ListBox состоит из строки и изображения. Я хочу что бы при изменении SelectedIndex на выденной строке поменялось изображение. Текст и изображение биндятся из ObservedCollection. При событии SelectionChanged у выбранного элемента меняется свойство ImagePath. Я реализовал, но изображения почему то не обновляются. Подскажите, что я сделал не так? ниже привожу XAML и код | Код | <Popup x:Name="_currency" HorizontalOffset="20" VerticalOffset="100" Opacity="0.6"> <Grid x:Name="_toastContainer" VerticalAlignment="Bottom" Width="430" Height="600" > <Border BorderBrush="White" BorderThickness="4" Width="430"> <Border.Background> <SolidColorBrush Color="Black" Opacity=".9" /> </Border.Background> <StackPanel> <StackPanel> <ScrollViewer> <ListBox Height="500" Name="currencyBox" ItemsSource="{Binding Currencies,Mode=TwoWay,UpdateSourceTrigger=Default}" SelectionChanged="ListBox_SelectionChanged" > <ListBox.ItemTemplate> <DataTemplate> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="330"/> <ColumnDefinition Width="*"/> </Grid.ColumnDefinitions> <TextBlock Grid.Column="0" Text="{Binding name}" Margin="15,0,0,20" VerticalAlignment="Center" FontSize="{StaticResource PhoneFontSizeLarge}"/> <Image Grid.Column="1" HorizontalAlignment="Right" Source="{Binding ImagePath, Converter={StaticResource CurrencyImageConvert},Mode=TwoWay,UpdateSourceTrigger=Default}" Width="40" Height="40" Margin="15,0,0,0" VerticalAlignment="Center"/> </Grid> </DataTemplate> </ListBox.ItemTemplate> </ListBox> </ScrollViewer> </StackPanel> <StackPanel Orientation="Horizontal"> <Button Content="Add" Width="200"/> <Button Content="Cancel" Width="200"/> </StackPanel> </StackPanel> </Border> </Grid> </Popup>
|
| Код |
public class OptionsPageViewModel:INotifyPropertyChanged { private ObservableCollection<Currency> _Currency { get; set; } public OptionsPageViewModel() { OptionsList = new ObservableCollection<OptionViewModel>(); BbDb db = App.DataServer; _Currency = db.GetCurrencyList(); } public ObservableCollection<Currency> Currencies { get { return _Currency; } set { _Currency = value; NotifyPropertyChanged("Currencies"); } }
public void ImageChangeCurrency(int id) { Currencies[id].ImagePath = "/icons/active.png"; NotifyPropertyChanged("Currencies"); }
public event PropertyChangedEventHandler PropertyChanged; private void NotifyPropertyChanged(String propertyName) { PropertyChangedEventHandler handler = PropertyChanged; if (null != handler) { handler(this, new PropertyChangedEventArgs(propertyName)); } } }
|
| Код |
public class Currency { public Currency() { } public Currency(int Id, string Name) { id = Id; this.name = Name; } int _id; public int id { get { return _id; } set { _id = value; } } string _name; public string name { get { return _name; } set { _name = value; } }
string _image;
public string ImagePath { get { return _image; } set { _image = value; } } }
|
|