1

我正在使用 WPF Devexpress GridControl,并且我有一个包含图像的列。我想使用 DataTrigger 修改图像。这是 XAML:

      <dxg:GridColumn Header="{Binding Source={StaticResource MainWindowResources}, Path=Resource.Status}"
                                FieldName="SaveStatus"
                                MinWidth="60"
                                Width="60"
                                ReadOnly="True" 
                                >
                    <dxg:GridColumn.CellTemplate>
                        <DataTemplate>
                            <Image HorizontalAlignment="Center"
                                   VerticalAlignment="Center"
                                   Style="{StaticResource ImageStatusStyle}">
                            </Image>
                        </DataTemplate>
                    </dxg:GridColumn.CellTemplate>

                </dxg:GridColumn>

和风格:

<Style TargetType="{x:Type Image}" x:Key="ImageStatusStyle">
    <Style.Triggers>
        <DataTrigger Binding="{Binding Path=Data.SaveStatus, UpdateSourceTrigger=
PropertyChanged}" Value="{x:Static enums:SaveState.DoneSuccesfuly}">
            <Setter Property="Source" Value="..\Icons\StatusOk.png" />
        </DataTrigger>
        <DataTrigger Binding="{Binding Path=Data.SaveStatus, UpdateSourceTrigger=
PropertyChanged}" Value="{x:Static enums:SaveState.DoneUnsuccesfuly}">
            <Setter Property="Source" Value="..\Icons\StatusError.png" />
        </DataTrigger>
    </Style.Triggers>
</Style>

这行不通。我究竟做错了什么?这个问题有更好的解决方案吗?

4

2 回答 2

2

我设法找到了解决方案。问题是数据触发器绑定而不是 Data.SaveStatus 应该是 RowData.Row.SaveStatus:

 <Style.Triggers>
                <DataTrigger Binding="{Binding Path=RowData.Row.SaveStatus, UpdateSourceTrigger=PropertyChanged}" Value="{x:Static enums:SaveState.DoneSuccesfuly}">
                    <Setter Property="Source" Value="..\Icons\StatusOk.png"></Setter>
                </DataTrigger>
                <DataTrigger Binding="{Binding Path=RowData.Row.SaveStatus, UpdateSourceTrigger=PropertyChanged}"  Value="{x:Static enums:SaveState.DoneUnsuccesfuly}">
                    <Setter Property="Source" Value="..\Icons\StatusError.png"></Setter>
                </DataTrigger>
            </Style.Triggers>
于 2013-08-21T11:29:15.583 回答
0

尝试像这样访问您的图像:

<Style TargetType="{x:Type Image}" x:Key="ImageStatusStyle">
    <Style.Triggers>
        <Setter Property="Source" Value="/ApplicationName;component/Icons/StatusOk.png" />
        <DataTrigger Binding="{Binding Path=Data.SaveStatus, UpdateSourceTrigger=
PropertyChanged}" Value="{x:Static enums:SaveState.DoneUnsuccesfuly}">
            <Setter Property="Source" Value="/ApplicationName;component/Icons/StatusError.png" />
        </DataTrigger>
    </Style.Triggers>
</Style>
于 2013-08-21T09:06:49.323 回答