【发布时间】:2022-01-12 21:39:36
【问题描述】:
我在 ListBox 中有一个 ItemTemplate,其中包含 Image(国家标志)和 TextBlock(国家名称)
列表框:
<ListBox x:Name="countriesList" Background="#a79473" Foreground="#e6d9c4">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" Height="40" Background="#a79473">
<Image Source="{Binding Flag.Source}"/>
<TextBlock Text="{Binding Name}" Foreground="#e6d9c4" FontSize="20"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
国家级:
public class Country
{
public string Name { get; set; }
public Image Flag { get; set; }
public Country()
{
Flag = new Image();
}
}
当国家改变国旗时,一切正常,但当名称改变时,没有任何反应,
我想当我更改名称时,绑定仍然绑定到旧名称,但是如何处理呢?
Country country = new Country();
countriesList.Items.Add(country);
country.Name = "test";
country.Flag.Source = flagImage.Source;
附注这是我关于stackoverflow的第一个问题,我希望我在任何地方都没有犯错:)
【问题讨论】: