Click here to Skip to main content
15,885,435 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,
I am back again... :):( i am a lone tech person working in a team and have no one to help apart from you guys and Mr. Google. i am learning WPF now and created an application. it is working fine in view and code separated.
It extracts details from a web site. list out all the details of the product and their specifications and dump it all in an excel. so far all is good.
now i want to databind the view of giving the look and the progress to the user.
i am able to get the values out from the class and displaying in the lable. i want to show how much of each web is loaded by changing the color of the lable.
i want to show the state "Loading" "Interactive" ETC. to the user with change in color in the same lable.
i am able to get the string to the lable but the color change is not happening or triggering.
MY cut down XAML code:
start of XAML:(thought this might be important)

XML
<Window x:Class="WebExtractor.AvnetMainClass"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:Avenet_Web_Extractor.WebExtractor"
    xmlns:diag="clr-namespace:System.Diagnostics;assembly=WindowsBase"
    Title="Avnet Product Details Extractor" 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" Height="300" Width="538" 
    ResizeMode="NoResize">
    
    <Window.Resources>
        <local:ColorConvert x:Key="colorConvert"/>
        
    </Window.Resources>




part of the code where binding is happening
XML
<StackPanel Margin="164,4,4,5" HorizontalAlignment="Stretch" >
                        <Label Name="lbl1PrdFll" BorderBrush="Black" BorderThickness="1" Width="312" Height="27" Margin="0,2,0,0" Background="{Binding RelativeSource={RelativeSource Self}, Path=Caption,Converter={StaticResource colorConvert}}" Content="{Binding Path=prdFrstState, UpdateSourceTrigger=PropertyChanged}" ></Label>
                        <Label Name="lbl2PrdFll" BorderBrush="Black" BorderThickness="1" Width="312" Height="27" Margin="0,2,0,0" Background="{Binding RelativeSource={RelativeSource Self}, Path=Caption,Converter={StaticResource colorConvert}}"  Content="{Binding Path=prdScndState, UpdateSourceTrigger=PropertyChanged}"></Label>
                        <Label Name="lbl3PrdFll" BorderBrush="Black" BorderThickness="1" Width="312" Height="27" Margin="0,2,0,0" Background="{Binding RelativeSource={RelativeSource Self}, Path=Caption,Converter={StaticResource colorConvert}}"  Content="{Binding Path=prdLstState, UpdateSourceTrigger=PropertyChanged}"></Label>
 </StackPanel>


my vb.net code to convert the color

VB
Namespace WebExtractor

    <ValueConversion(GetType(String), GetType(SolidColorBrush))> _
    Public Class ColorConvert
        Implements IValueConverter
        Public Function Convert(ByVal value As Object, ByVal targetType As Type, ByVal parameter As Object, ByVal culture As CultureInfo) As Object Implements IValueConverter.Convert
            Dim boundWord As String = TryCast(value, String)
            Dim returnBrush As SolidColorBrush = Nothing
            Select Case boundWord.ToLower().Trim()

                Case "UnInti"
                    returnBrush = New SolidColorBrush(Colors.Red)
                Case "Loading"
                    returnBrush = New SolidColorBrush(Colors.Red)
                Case "Loaded"
                    returnBrush = New SolidColorBrush(Colors.LightPink)
                Case "Interactive"
                    returnBrush = New SolidColorBrush(Colors.Pink)
                Case "Complete"
                    returnBrush = New SolidColorBrush(Colors.Green)
            End Select
            
            Return returnBrush
        End Function

        Public Function ConvertBack(ByVal value As Object, ByVal targetType As Type, ByVal parameter As Object, ByVal culture As CultureInfo) As Object Implements IValueConverter.ConvertBack
            Throw New Exception("Cant convert back")
        End Function
    End Class
End Namespace


can you please correct me
Posted
Updated 27-Feb-13 19:12pm
v2
Comments
Manu_vish 28-Feb-13 4:56am    
I ma able to do this with text-block. not sure why not in labels. any one have any idea??
Matej Hlatky 28-Feb-13 4:58am    
What is “Caption” property at the Label.Background binding – why no “Content”, or better VM’s “prdFrstState”? Why are you binding to Self?
Did you tried to place break point into your ColorConvert. Convert method and check provided value?
Also UpdateSourceTrigger=PropertyChanged is useless in Label, because it only displays data.
Manu_vish 28-Feb-13 5:27am    
Sorry.because of confusion I typed caption. It is actually content. as mentioned I change value of labels to loading, opening. Etc. So wanted to change colors as per text. Ya. I placed breaks. But it never hit that sub. I used snoop now and came to know that there is eror in getting values from content

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