سيلفرلايت: تحديث مربع القائمة البند قالب

StackOverflow https://stackoverflow.com/questions/816724

  •  03-07-2019
  •  | 
  •  

سؤال

ولدي مربع القائمة وعلى الحدث انقر فوق I فتح لوحة جديدة حيث أقوم بتغيير البيانات من مربع القائمة، على نحو أدق مصدر الصورة. لدي مشكلة كيفية تحديث مربع القائمة لديك صورة جديدة. شكرا لك مقدما. هنا هو رمز بلادي:

<ListBox x:Name="lbNarudzbe" MouseLeftButtonUp="lbNarudzbe_MouseLeftButtonUp" HorizontalAlignment="Center" MaxHeight="600">
                    <ListBox.ItemTemplate>
                        <DataTemplate>
                            <StackPanel Orientation="Horizontal">
                                <Image Margin="0,5,0,0" Width="50" Height="50" HorizontalAlignment="Center" Source="{Binding Path=Picture}" />
                                <TextBlock HorizontalAlignment="Center" FontSize="23" Text="{Binding Path=UkupnaCijena}" Width="80"/>
                            </StackPanel>
                        </DataTemplate>
                    </ListBox.ItemTemplate>
                </ListBox>




public partial class Page : UserControl
    {
        ObservableCollection<Narudzba> narudzbe = new ObservableCollection<Narudzba>();

        public Page()
        {
            InitializeComponent();

            narudzbe.Add(new Narudzba());
            narudzbe.Add(new Narudzba());
            narudzbe.Add(new Narudzba());
            narudzbe.Add(new Narudzba());

            lbNarudzbe.ItemsSource = narudzbe;

        }





     public class Narudzba
            {
               //...
                public string Picture
                {
                    get { return "picture source"; }
                }.....
هل كانت مفيدة؟

المحلول

و
أساسا عندما تريد تحديث الصورة في مربع القائمة، تقوم بتحديث الخاصية صورة من الدرجة Narudzba الخاص بك، ومنذ الطبقة Narudzba الخاص بك لا يطبق INotifyPropertyChanged واجهة مربع القائمة لا يمكن تحديث الصورة.

إليك بعض التعليمات البرمجية التي قد تساعد.

    public class Narudzba : System.ComponentModel.INotifyPropertyChanged
{
    public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;
    void Notify(string propName)
    {
        if (PropertyChanged != null)
        {
            PropertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs(propName));
        }
    }

    string _picturesource;

    public string Picture
    {
        get { return _picturesource; }
        set 
        { 
            _picturesource = value;
            Notify("Picture");
        }
    }

    public Narudzba(string picturesource)
    {
        _picturesource = picturesource;
    }
  }
}

ثم رمز الحدث lbNarudzbe_MouseLeftButtonUp ينبغي أن تبدو هذه

    private void lbNarudzbe_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
    {
        Narudzba nb  = (Narudzba)lbNarudzbe.SelectedItem;
        nb.Picture = "http://somedomain.com/images/newpicture.jpg";            
    }

وHTH.

نصائح أخرى

ولست متأكدا رغم ذلك، ولكن يمكن أن لا يكون لديك نفس ملزمة للكائن imageblock خارج مربع القائمة واحد داخله؟

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top