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

Create Dyamic Icons in WPF Listbox Control

$
0
0

Hello. I am trying to create a listbox with icons in the first column. These icons have already been defined as resources contained in a resource dictionary. When I do this manually it shows an icon correctly..

What I'm trying to do is change the fill of the rectangle to a resource in the datatemplate to match the content from the database. (So if I added another record the icon could be a  blue circle, for example)

Can someone tell me how to bind the dynamic resource name to a property to the object in the listbox's items collection? Thanks in advance!

The itemssource for this listbox is using linq:

 

DimdbAsNewDataClassesDataContext


        lstSelect.ItemsSource = db.Components


My XAML for the listbox is:

<ListBoxx:Name="lstSelect"HorizontalAlignment="Left"Height="213"Margin="10,36,0,0"VerticalAlignment="Top"Width="257">

           

<ListBox.ItemTemplate>

              

<DataTemplate>

                  

<StackPanelOrientation="Horizontal">


                       

<RectangleName="ComponentIcon"Height="20"Width="20"Fill="{DynamicResourceFeatureIcon}"/>


                       

<TextBlockName="ComponentName"Text="{BindingPath=Name}"Margin="10,0,0,0"/>


                   

</StackPanel>


               

</DataTemplate>


           

</ListBox.ItemTemplate>


       

</ListBox>






Viewing all articles
Browse latest Browse all 18858

Trending Articles



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