我有一个带有两列的telerik rad网格,1。isconstraint,2。数量
isconstraint是一个散布真或假的bool。 数量是int
我的要求是,如果isconstraint为false,则将数量列中的0转换为图像或颜色画笔。
我尝试使用IvalueConverter。我试图将Isconstraint作为转换器参数传递。在运行时,它是成功的,但没有加载页面。请有人帮我解决这个问题。非常感谢你。 我的代码看起来像这样。
<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;
}
}
答案 0 :(得分:0)