【发布时间】:2018-07-09 18:20:57
【问题描述】:
就像标题所说的,我想通过单击按钮从选定的列表框项中获取属性的值
<ListBox x:Name="IconListbox" Background="{x:Null}" BorderBrush="Black">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal"/>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBoxItem x:Name="defaultIcon">
<Grid Background="Black">
<Border BorderBrush="#FF1EF3F3" BorderThickness="2">
<Image x:Name="defaultIconImage" Width="50" Height="50" Source="icon.png"/>
</Border>
</Grid>
</ListBoxItem>
<ListBoxItem>
<Grid Background="Black">
<Border BorderBrush="#FF1EF3F3" BorderThickness="2">
<Image x:Name="secondIconImage" Width="50" Height="50" Source="SecondIcon.png"/>
</Border>
</Grid>
</ListBoxItem>
</ListBox>
例如,如果我单击按钮,它应该返回当前所选项目的图像源。所以如果 ListboxItem defaultIcon 被选中,它应该返回 defaulticon.png。我该怎么做?
编辑:
也许我通过尝试使用列表框采取了错误的方法。我对 Xaml 代码非常陌生,我会尝试更好地解释我想要的结果。
这是我将用来尝试解释的图片:Image
So what i want is when 1 is selected i need it to return the source of the blue flame image when i click the save button
when 2 is selected i need it to return the source of the blue facebook image when i click the save button
【问题讨论】:
-
您好像忘记分享代码了。
-
我认为代码在那里?我只能向您展示 Xaml 代码,因为我不知道如何从按钮上的列表框中获取值按下按钮什么也不做^^
标签: c# wpf xaml listbox listboxitem