0

I have a telerik rad grid with two columns, 1. isconstraint, 2. Quantity

isconstraint is a bool which dislays true or false. quantity is int

My requirment is to convert 0's in the quantity column to an image or a color brush if the isconstraint is false.

I tried using IvalueConverter. I tried to pass the Isconstraint as a converterparameter.while running, it is bulding sucessfully, but not loading the page. can anyone help me out with this please. thank you very much. My code looks like this.

 <telerik:GridViewDataColumn DataMemberBinding="{Binding LastQtyAvail}"                                                                                
                                                Width="130"                                             
                                                IsReadOnly="True" TextAlignment="Right" HeaderTextAlignment="Center">
                                                <telerik:GridViewDataColumn.CellTemplate>
                                                            <DataTemplate>
                                                        <StackPanel Orientation="Horizontal">
                                                            <Image x:Name="img" Visibility="Visible" Source="{Binding LastQtyAvail,Converter={StaticResource QuantityToImageConverter},ConverterParameter={Binding IsConstraint}}" Width="100" Height="100"/>
                                                            <TextBlock Text="{Binding LastQtyAvail}">
                                                            </TextBlock>
                                                        </StackPanel>
                                                            <!--<Border BorderThickness="1"
                                                                        CornerRadius="5"
                                                                        VerticalAlignment="Top"
                                                                        BorderBrush="Black"
                                                                        Margin="0"
                                                                        Background="{Binding LastQtyAvail, 
                                                                        Converter={StaticResource QuantityToImageConverter},ConverterParameter={Binding IsConstraint}}">                                                                

                                                                <Image x:Name="img" Visibility="Visible" Source="{Binding LastQtyAvail,Converter={StaticResource QuantityToImageConverter},ConverterParameter={Binding IsConstraint}}" Width="100" Height="100"/>
                                                            <TextBlock Text="{Binding LastQtyAvail}">
                                                            </TextBlock>
                                                        </Border>-->

                                                    </DataTemplate>
                                                </telerik:GridViewDataColumn.CellTemplate>

                                            </telerik:GridViewDataColumn>

<telerik:GridViewDataColumn DataMemberBinding="{Binding IsConstraint, Mode=TwoWay}" HeaderTextAlignment="Center"                                                                                
                                                IsGroupable="False" IsVisible="{Binding IsColumnVisibleToCustomer, Source={StaticResource PFOViewModel}}"
                                                IsReadOnly="{Binding CanExecuteProductUpdateConstrain, Converter={StaticResource BooleanNotConverter}, Mode=OneWay}"
                                                Background="#77ADD8E6"                                                                                
                                                Width="74" />

And the valueconverter cs file is

public class QuantityToImageConverter : IValueConverter
    {

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            //string path = string.Empty;
            //int result = (int)value;

            //string falsePath = "/Brightstar.VSO;component/Assets/DataGrid/False.png";

            //if (parameter == null)
            //{
            //    //int imagePaths = Convert.parameter.ToString().Split('|');
            //    //if (imagePaths.Length == 2)
            //    //{
            //    //    truePath = imagePaths[0];
            //    //    falsePath = imagePaths[1];
            //    //}
            //}

            //if (parameter != null)
            //{
            // // int imagePaths = Convert.parameter.ToString().Split('|');
            //    int imagePaths = Convert.Parameter.Tostring().Split('1');
            //    if (imagePaths.Length == 2)
            //    {

            //        falsePath = imagePaths[1];
            //    }
            //}


            ////if (result==0 && )
            ////{

            ////}
            ////else
            ////{
            ////    path = falsePath;
            ////}



            Int32 id = System.Convert.ToInt32(value);

            LinearGradientBrush brush = new LinearGradientBrush();
            brush.StartPoint = new Point(0, 1);
            brush.EndPoint = new Point(0, 0);
            brush.GradientStops.Add(new GradientStop()
            {
                Color = Colors.White,
                Offset = 0
            });
            brush.GradientStops.Add(new GradientStop()
            {
                Color = Color.FromArgb(
                    200,
                    System.Convert.ToByte((id * 103) % 256),
                    System.Convert.ToByte((id * 157) % 256),
                    System.Convert.ToByte((id * 233) % 256)
                ),
                Offset = 1
            });

            return brush;


            //ImageSourceConverter conv = new ImageSourceConverter();
            //return conv.ConvertFromString(falsePath);
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            return 0;
        }
    }
Karthik
  • 115
  • 1
  • 12

1 Answers1

0

I resolved it by following the below link

http://www.scottlogic.co.uk/blog/colin/2009/06/silverlight-multibindings-how-to-attached-mutiple-bindings-to-a-single-property/

it works for me...

Karthik
  • 115
  • 1
  • 12