我有一个WPF Caliburn.Micro应用程序。我曾经有一个DataGrid,下面是代码的一部分:
<DataGrid x:Name="FirstEntries" Grid.Row="5"
AutoGenerateColumns="False"
BaseControls:DataGridExtension.Columns="{Binding FirstEntryGridColumns}"
CanUserAddRows="False" IsReadOnly="True"
SelectedItem="{Binding Path=SelectedFirstEntry}">
<DataGrid.Resources>
<conv:StatusToBackgroundColorConverter x:Key="StatusToBackgroundColor"/>
</DataGrid.Resources>
<DataGrid.ItemContainerStyle>
<Style TargetType="{x:Type DataGridRow}">
<Style.Setters>
<Setter Property="Background" Value="{Binding Path=Status, Converter={StaticResource StatusToBackgroundColor}}"></Setter>
<Setter Property="cal:Message.Attach" Value="[Event MouseDoubleClick] = [Action OnDoubleClickFirstEntry($dataContext)]"/>
</Style.Setters>
</Style>
</DataGrid.ItemContainerStyle>
您可以看到,每一行的背景色都绑定到状态字段值,并且处理了一个双击事件。现在我正在迁移到ComponentOne的FlexGrid,我不知道如何才能在那里实现同样的目标,因为FlexGrid似乎不了解ItemContainerStyle。
你能帮我弄一下这个吗?谢谢。
发布于 2012-08-09 04:34:42
出于性能原因,C1 FlexGrid做了一些"WinFormsy“的事情,并且没有使用DependencyProperties或样式/模板,因此您不能使用数据触发器来设置行背景或设置您想要的事件的命令。他们的建议是使用Cell的mouseclick事件在代码中进行处理。
我的建议是,如果可能的话,回到WPF4.0的DataGrid并绑定to an ICollectionView to utilize it's Filtering function。链接了Bea Stollnitz的许多关于操作集合视图的教程。
发布于 2012-10-22 18:08:09
您是否看过CellFactory类和ICellFactory接口。我用它来设置不同的背景颜色,这取决于我的一个项目中的项状态。
Public Overrides Sub CreateCellContent(grid As C1.WPF.FlexGrid.C1FlexGrid, bdr As Border, rng As C1.WPF.FlexGrid.CellRange)
MyBase.CreateCellContent(grid, bdr, rng)
Dim infPre As InfPresenterTextEntity
infPre = CType(grid.Rows(rng.Row).DataItem, InfPresenterTextEntity)
If Not infPre Is Nothing Then
If infPre.IsNew Then
grid.Rows(rng.Row).Background = Brushes.LightGreen
ElseIf infPre.IsDirty Then
grid.Rows(rng.Row).Background = Brushes.LightYellow
End If
'grid.AutoSizeRow(rng.Row, 0)
'grid.AutoSizeRows(rng.Row, rng.Row, 0)
End if
End Subhttps://stackoverflow.com/questions/11852418
复制相似问题