简体   繁体   中英

c# listbox : change foreground color of the text

How do I change the color of the message in the if(InLine) block below in the code

public void showMessage(string message, bool InLine)
{
   if (InLine)
      messageBox.Items[messageBox.Items.Count-1] += message;
   else
   {
     ListBoxItem item = new ListBoxItem() { Content = message, Foreground = new SolidColorBrush(Colors.Red) };
     messageBox.Items.Add(item);
   }

}

its better using Animmation in Xaml:

<ListBox x:Name="messageBox">
    <ListBox.ItemContainerStyle >
        <Style TargetType="ListBoxItem" >
                     <Style.Triggers>
                <EventTrigger RoutedEvent="Loaded" >
                    <BeginStoryboard>
                        <Storyboard >
                            <ColorAnimation  Storyboard.TargetProperty="Background.Color" From="Red" To="Transparent" />
                        </Storyboard>
                    </BeginStoryboard>
                </EventTrigger>
            </Style.Triggers>
        </Style>
    </ListBox.ItemContainerStyle>
</ListBox>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM