locked
foreground color change. RRS feed

  • Question

  • Hi all, I am new in windows phone 7 app development.my issue is m want to change textblock color.textblock display data through binding.my xaml is

                                                                                                                          

    <ListBox  Name="lstProducts" ItemsSource="{Binding}" Margin="10,10,10,70" SelectionChanged="lstProducts_SelectionChanged" LayoutUpdated="lstProducts_LayoutUpdated">

                    <ListBox.ItemTemplate>


                        <DataTemplate>
                            <Border Margin="0" Padding="5" Background="White" 
              BorderBrush="Gray" BorderThickness="0.75" CornerRadius="10"
              VerticalAlignment="Top">
                                <StackPanel Orientation="Vertical" Width="460" Height="200">

                                    <StackPanel Orientation="Horizontal"  >
                                        <!--<toolkit:GestureService.GestureListener>
                                                <toolkit:GestureListener   Flick="GestureListener_Flick"  />
                                            </toolkit:GestureService.GestureListener>-->

                                        <TextBlock Text="{Binding ProductName}" Tag="{Binding InventoryID}"  Width="150"  Margin="10,0,0,0" Foreground="Black" FontWeight="Bold">

                                        </TextBlock>
                                        <Image Source="{Binding Image}" Height="20" Width="20" Margin="0,5,0,0" VerticalAlignment="Top"/>

                                        <TextBlock Width="150"  Foreground="Gray" Margin="110,0,0,0"  TextAlignment="Right">
                                           <Run Text="{Binding CategoryText}"/>

                                        </TextBlock>
                                    </StackPanel>
                                    <StackPanel Orientation="Horizontal"  Margin="0,10,0,0">
                                        <TextBlock Text="UPP:"  Width="40" Foreground="Black" Margin="10,10,0,0"/>
                                        <Image Source="{Binding CurrencySymbol}" Height="20" Margin="0,15"  Name="SymbolImage" VerticalAlignment="Top" Width="20"/>
                                        <TextBlock Text="{Binding UPP}"   Width="150"  Foreground="Black" Margin="0,10,0,0"  />
                                        <TextBlock Text="USP:"  Width="40" Foreground="Black" Margin="80,10,0,0"/>
                                        <Image Source="{Binding CurrencySymbol}" Height="20" Margin="0,15"  Name="SymbolImage1" VerticalAlignment="Top" Width="20" />
                                        <TextBlock Text="{Binding USP}"   Width="80"  Foreground="Black" Margin="0,10,0,0" TextAlignment="Right"/>
                                    </StackPanel>
                                    <StackPanel Orientation="Horizontal"  Margin="0,0,0,0">
                                        <TextBlock Width="215"  Foreground="Black" Margin="10,0,0,0">
                                            <Run Text="{Binding AvlQty}"/>
                                            <Run Text="{Binding Units}"/>
                                        </TextBlock>
                                        <TextBlock Width="215"   Margin="0" Foreground="{Binding TitleColor}" TextAlignment="Right">
                                            <Run Text="{Binding ActionType}"/>
                                            <Run Text="{Binding Qty}"/>
                                            <Run Text="{Binding Units}"/>
                                        </TextBlock>
                                    </StackPanel>
                                    <StackPanel Orientation="Vertical"  Margin="0,10,0,0">
                                        <TextBlock Width="350" Foreground="Black" Margin="10,0,110,0" TextAlignment="Left">
                                            <Run Text="{Binding CurrentAvlQty}"/>
                                            <Run Text="{Binding Units}"/>
                                        </TextBlock>
                                        <TextBlock Width="350"  Foreground="Black" Margin="10,10,110,0" TextAlignment="Left">
                                            <Run Text="{Binding Date}"/>

                                        </TextBlock>
                                    </StackPanel>

                                </StackPanel>

                            </Border>
                        </DataTemplate>
                    </ListBox.ItemTemplate>
                </ListBox>

    and my code is=

      string data = "SELECT I.InventoryOrderID AS InventoryOrderID,P.ProductName AS ProductName,P.ProductID AS ProductID,C.CategoryID AS CategoryID,'('||C.CategoryText||')' AS CategoryText,I.UnitPurchasePrice AS UPP,I.UnitSalePrice AS USP,'Avl Qty: '||'0.00' AS AvlQty,I.AddedQuantity AS Qty,'Cur Avl Qty: '||I.AddedQuantity AS CurrentAvlQty ,'Added On:'||I.DateAdded AS Date,'Added Qty: ' AS ActionType,'1' AS IsTrackingOn,U.UnitID AS UnitID,U.Units AS Units,'Images/inventoryindicator.png' AS Image,(select 'Images' || '/' || substr(CurrencySymbol,-100,100) ||'.png'  as CurrencySymbol from Currency where IsActive=1 and IsDefault=1) as CurrencySymbol FROM InventoryOrder I LEFT JOIN Products P ON I.ProductID=P.ProductID LEFT JOIN Units U ON U.UnitID=I.UnitID LEFT JOIN Category C ON I.CategoryID=C.CategoryID UNION SELECT  SD.InventoryOrderID AS InventoryOrderID,P.ProductName AS ProductName,P.ProductID AS ProductID,C.CategoryID AS CategoryID,'('||C.CategoryText||')' AS CategoryText,CASE WHEN I.InventoryOrderID>0 THEN I.UnitPurchasePrice ELSE P.PurchasePrice END AS UPP, SD.UnitSalePrice AS USP,'Avl Qty: '||SD.AvailableInventory AS AvlQty, SD.Quantity as Qty,'Cur Avl Qty: '||(SD.AvailableInventory-SD.Quantity) AS CurrentAvlQty ,'Sold On'|| SD.SoldDate AS Date,'Sold Qty: ' as ActionType, CASE WHEN I.InventoryOrderID>0 THEN '1' ELSE '0' END AS IsTrackingOn,U.UnitID AS UnitID,U.Units AS Units,CASE WHEN SD.InventoryOrderID>0 THEN 'Images/inventoryindicator.png' ELSE '' END AS Image,(select 'Images' || '/' || substr(CurrencySymbol,-100,100) ||'.png'  as CurrencySymbol from Currency where IsActive=1 and IsDefault=1) as CurrencySymbol FROM SalesDetails SD LEFT JOIN Products P ON SD.ProductID=P.ProductID LEFT JOIN InventoryOrder I on I.InventoryOrderID=SD.InventoryOrderID LEFT JOIN Units U ON U.UnitID=SD.UnitID LEFT JOIN Category C ON P.CategoryID=C.CategoryID ORDER BY Date DESC";
                alldata = (Application.Current as App).db.SelectObservableCollection<InventoryOrder>(data);

    lstProducts.ItemsSource = alldata;

    textblock which bind "Action Type",Action type have 2 value 1."Added Qty" and 2."Sold Qty:"

    so ,i want if "Action Type" value="Added Qty:" the foreground color of textblock will be green and if "Action Type" value="Sold Qty:" then foreground color of textblock will be red.

    pls help me to achieve this.

    Thanx in advance.

    Tuesday, August 14, 2012 11:35 AM

All replies