views:

52

answers:

2

In Silverlight, I have a Grid with DataContext set to class ViewModel.
The ViewModel contains list of items (each of them containing int ID and string Text) and an integer "ID", which identifies the currently active item (not selected item).
I would like to construct xaml with ListBox where activated item has another color. How can I do it?

Specifically, in xaml, I have:

<Grid DataContext="ModelView">
    <ListBox ItemsSource="Questions">
        <ListBox.ItemTemplate>           
            <TextBlock Text="{Binding ID}" />
            <TextBlock Text="{Binding Text}" />           
        </ListBox.ItemTemplate>
    </ListBox>
    <TextBlock Text="{Binding ID}" />
</Grid>`

How can set I the color of one (and only one) item in the listbox, based on property ID in ModelView?

One more problem - when I change active item - how can I refresh the ListBox?

A: 

I've in xaml: <Grid DataContext="ModelView"> <ListBox ItemsSource="Questions"> <ListBox.ItemTemplate>
<TextBlock Text="{Binding ID}" /> <TextBlock Text="{Binding Text}" />
</ListBox.ItemTemplate> </ListBox> <TextBlock Text="{Binding ID}" /> </Grid>

How set I color of one (and only one) item in th listbox based on property ID in ModelView?

Gabriel
@Gabriel: This type of additional info belongs in the question section. I went ahead and added it there. I suggest you delete this answer, improving the chances of getting a proper response.
mjv
How can I delete my answer?
Gabriel
A: 

Your ItemTemplate does not seem to be valid btw. !

I would try to use Triggers to template your highlighted Listbox Item

In a Grid i did this one for example

 <DataTemplate>
     <Image x:Name="MyImage" Source="Images/corrected.png" Width="64" Height="64" />
     <DataTemplate.Triggers>
        <DataTrigger Binding="{Binding YourConditionValue}" Value="0">
            <Setter TargetName="MyImage" Property="Source" Value="Images/notCorrected.png" />
         </DataTrigger>
      </DataTemplate.Triggers>
  </DataTemplate>

That might be a solution but you need to check it yourself

KroaX