Nie można uzyskać dostępu DataGridCell.Content
ten sposób, zamiast używać DataTrigger
na podstawie swojej DataGrid.SelectedItem.YourProperty
tak:
<DataGrid.CellStyle>
<Style TargetType="DataGridCell">
<Setter Property="FontWeight" Value="Bold" />
<Style.Triggers>
<DataTrigger Binding="{Binding YourProperty}" Value="0">
<Setter Property="FontWeight" Value="Normal"/>
</DataTrigger>
</Style.Triggers>
</Style>
</DataGrid.CellStyle>
EDIT:
Zakładając, że DataGridColumns
są tekstowy następnie można użyć IValueConverter
jak poniżej:
Należy pamiętać, że jeśli niektóre kolumny siatki danych nie są oparte na tekście , to rozwiązanie nadal działa dla tych kolumn, które są.
Xaml:
<Window.Resources>
<local:FontWeightConverter x:Key="fontWeightConverter"/>
</Window.Resources>
...
<DataGrid.CellStyle>
<Style TargetType="{x:Type DataGridCell}">
<Style.Setters>
<Setter Property="FontWeight"
Value="{Binding RelativeSource={RelativeSource Self},
Path=Content.Text,
Converter={StaticResource fontWeightConverter}}" />
</Style.Setters>
</Style>
</DataGrid.CellStyle>
Przelicznik:
public class FontWeightConverter : IValueConverter
{
public object Convert(object value, Type targetType,
object parameter, CultureInfo culture)
{
if (value != null && value.ToString() == "0")
return FontWeights.Normal;
return FontWeights.Bold;
}
public object ConvertBack(object value, Type targetType,
object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
Brzmi dobrze, ale potrzebuję go dla wszystkich właściwości mojego obiektu. Nie chcę replikować 12 razy tego kodu, który jestem pewny, że pracuję – Galma88
Perfect. Twoja edycja działa. Zakładam więc, że nie ma możliwości robienia tego tylko w XAML. Czy to jest poprawne? – Galma88
Jestem w 99% pewien, że nie ma;) –