WPF基于两个值动态更改图像源

时间:2017-01-13 09:59:07

标签: wpf image xaml devexpress datatrigger

我是WPF的新手,我试图显示2个版本的图像取决于其他Devexpress'gridcontrol列中的值。

我有gridcontrol,其中包含以下列:

                <dxg:GridColumn x:Name="iloscDoWydania" FieldName="IloscDoWydania" MinWidth="50" Width="50">
                <dxg:GridColumn.DisplayTemplate>
                    <dxg:DefaultControlTemplate>
                        <Label FontSize="20" FontWeight="SemiBold" Content="{Binding Path=RowData.Row.IloscDoWydania}"
                               HorizontalAlignment="Center" VerticalAlignment="Center"/>
                    </dxg:DefaultControlTemplate>
                </dxg:GridColumn.DisplayTemplate>
            </dxg:GridColumn>

            <dxg:GridColumn x:Name="iloscWydana" FieldName="IloscWydana" MinWidth="50" Width="50">
                <dxg:GridColumn.DisplayTemplate>
                    <dxg:DefaultControlTemplate>
                        <Label FontSize="20" FontWeight="SemiBold" Content="{Binding Path=RowData.Row.IloscWydana}"
                               HorizontalAlignment="Center" VerticalAlignment="Center"/>
                    </dxg:DefaultControlTemplate>
                </dxg:GridColumn.DisplayTemplate>
            </dxg:GridColumn>

            <dxg:GridColumn x:Name="status" FieldName="Status" MinWidth="50" Width="50">
                <DataTemplate>
                    <Image>
                        <Image.Style>
                            <Style TargetType="{x:Type Image}">
                                <Setter Property="Source" Value="/WMS;component/Resources/Ok-48.png" />
                                <Style.Triggers>
                                    <DataTrigger Value="True" Binding="{Binding Path=RowData.Row.IloscWydana, 
                                                                        Converter={StaticResource ResourceKey=StatusConverter}, 
                                                                        ConverterParameter={Binding Path=RowData.RowIloscDoWydania}}">
                                        <Setter Property="Source" Value="/WMS;component/Resources/Cancel-48.png"/>
                                    </DataTrigger>
                                </Style.Triggers>
                            </Style>
                        </Image.Style>
                    </Image>
                </DataTemplate>
            </dxg:GridColumn>

IloscDoWydania列的值小于IloscWydana时,我想显示“确定”图片。

这是我的转换器类:

public class CustomStatusConverter : IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        if (System.Convert.ToInt32(value) < System.Convert.ToInt32(parameter))
            return true;
        else
            return false;
    }

    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    {

        return DependencyProperty.UnsetValue;
    }
}

不幸的是我的自定义Convert方法没有触发。

0 个答案:

没有答案