Click here to Skip to main content
16,016,744 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
1. i have a textblock in the list which
2. i need to change the forground
of text
3. i need to change the background image of the textblock

my problem is i can,t change both text and image
if anyone know about this please help me to slove this problem

XAML
ListView.ItemTemplate>
                <DataTemplate x:DataType="local:studentItem">
                    <Grid>

                        <StackPanel x:Name="stacklist" >
						<TextBlock  x:Name="statuslist" Grid.Column="2" text="default"
                       FontSize="14"
                       FontWeight="SemiBold"
                        Foreground="gray"
                       Height="auto"
                      HorizontalAlignment="Left"
                       Width="200"
                       Margin="0,20,0,0" DataContextChanged="statuslist_DataContextChanged" >
                                    <InlineUIContainer>
                                        <Image x:Name="statusimage" Source="Assets/searchtraineee.png" />
                                    </InlineUIContainer>

                                </TextBlock>
                       </Grid>
                </DataTemplate>
            </ListView.ItemTemplate> 


What I have tried:

C#
     void Loadstudent()
{

    List<studentItem> studentlist = DataAccess.Getstudents(studentCourseList);
    BitmapImage One = new BitmapImage(new Uri("ms-appx:///Assets/image1.png"));
    BitmapImage Two = new BitmapImage(new Uri("ms-appx:///Assets/image2.png" ));
        foreach (studentItem tplan in studentlist)
        {
        if (tplan.ProcStatus == 1)
        {
             statuslist.text = "completed";
             statusimage.Source = One;
        }
        if (tplan.ProcStatus == 2)
        {
             statuslist.text = "notcompleted";
             statusimage.Source = Two;
        }
}
}
Posted
Updated 8-Jan-23 20:12pm
v3
Comments
[no name] 10-Jan-23 1:09am    
Put the image behind the textblock (i.e. both in the same grid cell). The background of a textblock is always transparent in UWP.

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