【发布时间】:2015-08-27 13:19:43
【问题描述】:
我有 WPF 数据网格:
<DataGrid IsReadOnly="True" x:Name="PivotDataGridView" Grid.Row="1" Grid.ColumnSpan="3" Margin="5,30,10,20" CanUserSortColumns="False" CellStyle="{StaticResource PivotCellStyle}" Grid.Column="1">
当我选择某行时,它看起来像这样:
http://i.stack.imgur.com/36d4X.png
有人知道怎么解决吗?
编辑:
这里是使用的样式:
<Style x:Key="PivotCellStyle" TargetType="DataGridCell">
<Setter Property="Background" Value="{Binding RelativeSource={RelativeSource Self}, Converter={StaticResource DifferenceToTotalBrushConverter}}" />
</Style>
这里是转换器:
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
DataGridCell currentCell;
try
{
var context = (value as DataGridCell).DataContext;
var Prices = (context as PivotDataGridViewItem).Price;
currentCell = value as DataGridCell;
if (currentCell.Column.DisplayIndex > 3 && currentCell.Column.DisplayIndex % 2 == 0)
{
int index = GetIndexPrices(currentCell);
if(index < Prices.Count)
{
decimal currentPrice = Prices[index];
decimal totalPrice = Prices[0];
if (currentPrice != 0)
{
if (Math.Abs(currentPrice - totalPrice) < 0.20m && currentPrice != totalPrice)
{
return MainWindow.PivotCentPriceColor;
}
else if (currentPrice < totalPrice)
{
return MainWindow.PivotLowerPriceColor;
}
else if (currentPrice > totalPrice)
{
return MainWindow.PivotHigherPriceColor;
}
}
}
}
}
catch (InvalidCastException)
{
return DependencyProperty.UnsetValue;
}
catch (NullReferenceException)
{
return DependencyProperty.UnsetValue;
}
catch (FormatException)
{
}
return DependencyProperty.UnsetValue;
}
不实施 ConvertBack 会不会有问题?
【问题讨论】:
-
我想这取决于您的 DataGrid 的样式,或者可能取决于 Cell 的样式。你应该发布一些关于它的额外信息......