Silverlight:更新列表框模板项
我有列表框,在单击事件时我打开新面板,在其中更改列表框的数据,更准确地说是图像源。 我在如何更新列表框以获取新图片时遇到问题。 提前致谢。 这是我的代码:
<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"; }
}.....
I have listbox and on click event I open new panel where i change data of listbox, more accurately image source. I have problem how to update listbox to have new picture. Thanks in advance.
Here is my code:
<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"; }
}.....
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
基本上,当您想要更新列表框中的图片时,您正在更新 Narudzba 类的 Picture 属性,并且由于您的 Narudzba 类没有实现 INotifyPropertyChanged 接口,因此列表框无法更新图片。
这是一些可能有帮助的代码。
那么 lbNarudzbe_MouseLeftButtonUp 事件代码应如下
HTH 所示。
Basically when you want to update the picture in the listbox, you are updating the Picture property of your Narudzba class, and since your Narudzba class does not implement the INotifyPropertyChanged interface the listbox can't update the picture.
Here's some code that might help.
Then the lbNarudzbe_MouseLeftButtonUp event code should look like this
HTH.
虽然不确定,但是列表框外部的图像块对象和列表框内部的图像块对象不能有相同的绑定吗?
Not sure though, but can you not have same binding for the imageblock object outside the listbox and the one inside it?