2013-02-22 68 views
0

我有兩列,1 isconstraint,2.數量轉換0到圖像

isconstraint是dislays真或假一個bool一個Telerik的弧度網格。 數量爲int

我的需求是如果isconstraint爲false,則將quantity列中的0轉換爲圖像或顏色刷。

我試過使用IvalueConverter。我嘗試通過Isconstraint作爲converterparameter.while在運行時,它是成功建立的,但不加載頁面。任何人都可以幫我解決這個問題。非常感謝你。 我的代碼看起來像這樣。

<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" /> 

而且valueconverter CS文件

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; 
     } 
    } 

回答