Click here to Skip to main content
15,884,047 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi everyone
I have a DataTemplate :

<DataTemplate x:Key="autoCompleteTemplate">
          <Grid TextElement.FontSize="18">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="1*" />
                    <ColumnDefinition Width="84" />
                </Grid.ColumnDefinitions>
                <Border Background="#FFFFFBDF">
                    <TextBlock Text="{Binding ItemName}" />
                </Border>
                <Border Grid.Column="1" Background="#FFFFFBDF">
                    <TextBlock Text="{Binding Balance,StringFormat=0.00}" />
                </Border>
            </Grid>
</DataTemplate>

i need to change the Background of the 2 borders inside the template when the ListBoxItem is selected

What I have tried:

I tried using an ItemContainerStyle by setting the properties of the Selected State using blend
so far i could change the color of the Background of the ListBoxItem as a whole when it's Selected but i only want to change the color of the inside borders of the content control which i can't access from the ItemContainerStyle
I also tried to make a separate DataTemplate for the Selected appearance
and tried to set the ContentControl in the Selected State To it , but that makes no difference

there is also the tiresome solution of using DataTriggers
basically to add an IsSelected Property to my Item Class
and implement INotifyPropertyChanged in it
and Set this property to True whenever the item Is Selected
and set the dataTemplate in the Trigger accordingly

but is there no other solution using XAML and Blend ,without having to change my class ?
Posted
Updated 16-Sep-16 6:03am
v5
Comments
Richard Deeming 16-Sep-16 11:38am    
The site seems to have swallowed your code block. It's a bug that's being worked on at the moment.

To work around it, please encode your code before posting - <&lt;, >&gt;, and &&amp;
Ahmad_kelany 16-Sep-16 12:04pm    
thanks very much , I kept updating the question not knowing what's wrong :)
[no name] 16-Sep-16 12:10pm    
Why can't you use a DataTemplate Trigger?
Ahmad_kelany 16-Sep-16 12:15pm    
I can
i was hoping to find an easier solution using XAML and blend only without having to change the class
because not always i will be in a situation with access or privilege to modify the underlying class
[no name] 16-Sep-16 13:24pm    
That makes no sense. A DataTemplate trigger IS XAML so I don't know what you mean that you would have to change the class because you don't.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900