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

unable to bind images to listbox and get the selected item in wpf

$
0
0

I need to show a collection of images horizontally in a listbox which i could achieve. however, the challenge am facing here is that am unable to bind the selected item(image) to the listbox-selected item property when I click or select any image in the listbox and get the selected image as well in code-behind.

the following is my xaml code and later is my xaml.cs code. Please let me know if I am missing something to fix the issue.

Thanks.

<ListBox Grid.Row="1" x:Name="ThumbnailPanel" ItemsSource="{Binding Frames}"
              SelectedItem="{Binding Path=MediaFrame,Mode=TwoWay}"
              ScrollViewer.CanContentScroll="True"
              ScrollViewer.VerticalScrollBarVisibility="Disabled"
              ScrollViewer.HorizontalScrollBarVisibility="Hidden"><ListBox.ItemsPanel><ItemsPanelTemplate><UniformGrid Columns="20" Rows="1"></UniformGrid></ItemsPanelTemplate></ListBox.ItemsPanel></ListBox>
public event PropertyChangedEventHandler PropertyChanged;

    public void OnPropertyChanged(string property)
    {
        var propertyChanged = PropertyChanged;
        if (propertyChanged != null)
        {
            propertyChanged(this, new PropertyChangedEventArgs(property));
        }
    }

    public ObservableCollection<Image> Frames { get; set; }

    public Image MediaFrame
    {
        get
        {
            return mediaFrame;
        }
        set
        {
            if (mediaFrame != value)
            {
                mediaFrame = value;
                OnPropertyChanged("MediaFrame");
            }
        }
    }

    private Image mediaFrame;

    if (Frames == null)
            {
                Frames = new ObservableCollection<Image>();

            }

    Frames.Add(
                new Image
                {
                    Source = imageSource,
                    ToolTip = _mediaPlayer.Position,
                    MaxWidth = _mediaPlayer.NaturalVideoWidth,
                    MaxHeight = _mediaPlayer.NaturalVideoHeight,
                    Margin = new Thickness(2)
                });

            ThumbnailPanel.DataContext = Frames;



Viewing all articles
Browse latest Browse all 18858

Trending Articles



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