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

Changing property of an element in a set of ListBoxItems?

$
0
0

I have a list box with a simple Ellipse I will use as an indicator and some text. I want to change the Fill of the ellipse depending on the state of an object relating to the text.

I can change the ellipse color of a named ellipse using a simple statement:

ellipse1.Fill = new SolidColorBrush(Colors.Red);


But how can I do this for an unknown number of unnamed objects in a list? I have the following graphic:

<ListBox Height="79" HorizontalAlignment="Left" Margin="220,173,0,0" Name="listBox1" VerticalAlignment="Top" Width="163"><ListBoxItem><StackPanel Orientation="Horizontal" Margin="0,0,5,0"><Ellipse Height="15" HorizontalAlignment="Left" Margin="2"  VerticalAlignment="Top" Width="15" Fill="Red"></Ellipse><TextBlock Margin="5,0,0,0">ListBox Item #1</TextBlock></StackPanel></ListBoxItem><ListBoxItem><StackPanel Orientation="Horizontal"><Ellipse Height="15" HorizontalAlignment="Left" Margin="2"  VerticalAlignment="Top" Width="15" Fill="Red"></Ellipse><TextBlock Margin="5,0,0,0">ListBox Item #2</TextBlock></StackPanel></ListBoxItem><ListBoxItem><StackPanel Orientation="Horizontal"><Ellipse Height="15" HorizontalAlignment="Left" Margin="2"  VerticalAlignment="Top" Width="15" Fill="Green"></Ellipse><TextBlock Margin="5,0,0,0">ListBox Item #3</TextBlock></StackPanel></ListBoxItem></ListBox>

How can I enumerate(?) through this structure and set the fill color appropriately?

And, as an added bonus point, if I wanted to insert instead of an ellipse an Image (PNG file) depending on the value, how could I do that?

Thanks from a C#/XAML Newbie!



Viewing all articles
Browse latest Browse all 18858

Trending Articles



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