IValueConverter的Convert方法没有调用 [英] IValueConverter's Convert method not invoking

查看:321
本文介绍了IValueConverter的Convert方法没有调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有网格,如果数量<我想要前景红色。 0。

我不允许在设计时在xaml中添加代码所以我运行时添加

绑定绑定=  new 绑定( 数量){Converter =  new  RedConverter()}; 
样式st = 样式( typeof (GridColumn));
st.Setters.Add( new Setter(Control.ForegroundProperty,binding));
_Left_Part_DE.Columns [ 数量]。Style = st;





和我的转换器类是



  public   class  RedConverter:IValueConverter 
{
public object 转换( object value ,输入targetType,
object 参数,CultureInfo文化)
{
返回 value .Convert_To_Number_DE< decimal>()< 0 ? Brushes.Red:Brushes.Black;
}

public object ConvertBack( object value ,输入targetType,
object 参数, CultureInfo culture)
{
throw new NotImplementedException();
}
}







问题是它没有发生任何错误也没有调用Convert方法

缺少

解决方案

你在列的样式设置器中设置绑定。但根据你的问题,你需要它用于单个细胞,而不是用于柱子。你的 _Left_Part_DE 是什么?如果它具有 CellStyle 之类的属性,请尝试使用它而不是 Style (在这种情况下,应更改样式目标类型另外)

绑定绑定= 绑定(  数量){Converter =  new  RedConverter()}; 
样式st = 样式( typeof (CellContentPresenter));
st.Setters.Add( new Setter(Control.ForegroundProperty,binding));
_Left_Part_DE.Columns [ 数量]。CellStyle = st;


 <   dx:gridcontrol    名称  = < span class =code-keyword> ctl_Grid    height   =  900   宽度  =  900    xmlns:dx   = #unknown >  
< dxg:gridcontrol.detaildescriptor xmlns:dxg = #unknown >
< dxg:datacontroldetaildescriptor name = ctlDataControlDetailDescriptor >
< dxg:datacontroldetaildescriptor.datacontrol >
< dx:gridcontrol autopopulatecolumns = name = ctl_Child_Grid >
< dxg:gridcontrol.view >
< dxg:tableview < span class =code-attribute> showgrouppanel = False autowidth = True navigationstyle = / >
< / dxg :gridcontrol.view >
< / dx:gridcontrol >
< / dxg:datacontroldetaildescriptor.datacontrol >
< / dxg:datacontroldetaildescriptor >
< / dxg:gridcontrol.detaildescriptor >
< dxg:gridcontrol.view xmlns:dxg = #unknown >
< dxg:tableview showgrouppanel = 错误 autowidth = True navigationstyle = / >
< / dxg:gridcontrol.view >
< / dx:gridcontrol >





c#part < br $>


 Style _Style =  new 样式( typeof运算(CellContentPresenter)); 
Setter _Setter = new Setter(); _
Setter.Property = CellContentPresenter.BackgroundProperty;
_Setter.Value = new 绑定( RowData.Row.Qty){Converter = new RedConverter()};
_Style.Setters.Add(_Setter); _
Left_Part_DE.Columns [ 数量]。CellStyle = Style;


I have grid and i want to color foreground red if Qty < 0 .
I am not allow to add code at design time in xaml So i run time add

Binding binding = new Binding("Qty") { Converter = new RedConverter() };
Style st = new Style(typeof(GridColumn));
st.Setters.Add(new Setter(Control.ForegroundProperty, binding));
_Left_Part_DE.Columns["Qty"].Style = st;



and my converter class is

public class RedConverter : IValueConverter
    {
        public object Convert(object value, Type targetType,
            object parameter, CultureInfo culture)
        {
            return value.Convert_To_Number_DE<decimal>() < 0 ? Brushes.Red : Brushes.Black;
        }

        public object ConvertBack(object value, Type targetType,
            object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }




problem is that it is not occurring any error nor invoking the Convert method
what is lacking

解决方案

you set binding in the style setter for column. But according your question, you need it for individual cell, not for column. What is your _Left_Part_DE? If it has property like CellStyle, try to use it instead of Style (in such case Style target type should be changed as well).

Binding binding = new Binding("Qty") { Converter = new RedConverter() };
Style st = new Style(typeof(CellContentPresenter));
st.Setters.Add(new Setter(Control.ForegroundProperty, binding));
_Left_Part_DE.Columns["Qty"].CellStyle = st;


<dx:gridcontrol name="ctl_Grid" height="900" width="900" xmlns:dx="#unknown">
            <dxg:gridcontrol.detaildescriptor xmlns:dxg="#unknown">
                <dxg:datacontroldetaildescriptor name="ctlDataControlDetailDescriptor">
                    <dxg:datacontroldetaildescriptor.datacontrol>
                        <dx:gridcontrol autopopulatecolumns="True" name="ctl_Child_Grid">
                            <dxg:gridcontrol.view>
                                <dxg:tableview showgrouppanel="False" autowidth="True" navigationstyle="Row" />
                            </dxg:gridcontrol.view>
                        </dx:gridcontrol>
                    </dxg:datacontroldetaildescriptor.datacontrol>
                </dxg:datacontroldetaildescriptor>
            </dxg:gridcontrol.detaildescriptor>
            <dxg:gridcontrol.view xmlns:dxg="#unknown">
                <dxg:tableview showgrouppanel="False" autowidth="True" navigationstyle="Row" />
            </dxg:gridcontrol.view>
        </dx:gridcontrol>



c# part

Style _Style = new Style(typeof(CellContentPresenter)); 
Setter _Setter = new Setter(); _
Setter.Property = CellContentPresenter.BackgroundProperty; 
_Setter.Value = new Binding("RowData.Row.Qty") { Converter = new RedConverter() }; 
_Style.Setters.Add(_Setter); _
Left_Part_DE.Columns["Qty"].CellStyle = Style;


这篇关于IValueConverter的Convert方法没有调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆