У меня есть объект SampleTypeRepresentation, который имеет логическое свойство "IsNew". Учитывая приведенное ниже древовидное представление, как мне покрасить объекты SampleTypeRepresentation с IsNew = true?
Спасибо за любую помощь по этому вопросу. Я знаю, что мне нужно реализовать какой-то стиль триггера, но я обнаружил, что ресурсы в сети немного сбивают с толку и до сих пор не повезло.
<TreeView x:Name="tvSTR" ItemsSource="{Binding SampleTypeRepresentations}" Height="445"
SelectedItemChanged="tvSTR_SelectedItemChanged" MouseDoubleClick="tvSTR_DoubleClick">
<TreeView.Resources>
<HierarchicalDataTemplate DataType="{x:Type local:SampleTypeRepresentations}" ItemsSource="{Binding Path=SampleTypeRepresentation}">
<TextBlock Text="{Binding Name}"/>
<HierarchicalDataTemplate.ItemTemplate>
<HierarchicalDataTemplate DataType="{x:Type local:SampleTypeRepresentation}" ItemsSource="{Binding Path=ChildSampleTypeRepresentations.SampleTypeRepresentation}">
<TextBlock Text="{Binding Name}"/>
</HierarchicalDataTemplate>
</HierarchicalDataTemplate.ItemTemplate>
</HierarchicalDataTemplate>
</TreeView.Resources>
</TreeView>
Вот классы этого блока кодовых ссылок. Это часть довольно большой иерархической структуры данных, но я думаю, что это должно дать вам представление о том, что происходит.
[XmlRoot(ElementName = "SampleTypeRepresentations", Namespace = "http://www.hilllaboratories.com/ns/clientrequestoptions")]
public class SampleTypeRepresentations
{
[XmlElement(ElementName = "SampleTypeRepresentation", Namespace = "http://www.hilllaboratories.com/ns/clientrequestoptions")]
public List<SampleTypeRepresentation> SampleTypeRepresentation { get; set; }
[XmlAttribute(AttributeName = "ID")]
public string ID { get; set; }
[XmlAttribute(AttributeName = "Name")]
public string Name { get; set; }
[XmlAttribute(AttributeName = "ReportingGroup")]
public string ReportingGroup { get; set; }
}
[XmlRoot(ElementName = "ChildSampleTypeRepresentations", Namespace = "http://www.hilllaboratories.com/ns/clientrequestoptions")]
public class ChildSampleTypeRepresentations : INotifyPropertyChanged
{
private ObservableCollection<SampleTypeRepresentation> sampleTypeRepresentation;
[XmlElement(ElementName = "SampleTypeRepresentation", Namespace = "http://www.hilllaboratories.com/ns/clientrequestoptions")]
public ObservableCollection<SampleTypeRepresentation> SampleTypeRepresentation { get => sampleTypeRepresentation;
set
{
sampleTypeRepresentation = value;
NotifyPropertyChanged();
}
}
public event PropertyChangedEventHandler PropertyChanged;
private void NotifyPropertyChanged([CallerMemberName] String propertyName = "")
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
[XmlRoot(ElementName = "SampleTypeRepresentation", Namespace = "http://www.hilllaboratories.com/ns/clientrequestoptions")]
public class SampleTypeRepresentation : INotifyPropertyChanged
{
//Controls highlighting in UI
[XmlIgnore]
public bool IsNew = false;
private ChildSampleTypeRepresentations childSampleTypeRepresentations;
private string name;
[XmlElement(ElementName = "Name", Namespace = "http://www.hilllaboratories.com/ns/clientrequestoptions")]
public string Name { get => name;
set
{
if (name == value)
{
return;
}
name = value;
NotifyPropertyChanged();
}
}
[XmlElement(ElementName = "SampleTypeInfo", Namespace = "http://www.hilllaboratories.com/ns/clientrequestoptions")]
public SampleTypeInfo SampleTypeInfo { get; set; }
[XmlElement(ElementName = "ChildSampleTypeRepresentations", Namespace = "http://www.hilllaboratories.com/ns/clientrequestoptions")]
public ChildSampleTypeRepresentations ChildSampleTypeRepresentations
{
get => childSampleTypeRepresentations;
set
{
if (childSampleTypeRepresentations == value)
{
return;
}
childSampleTypeRepresentations = value;
NotifyPropertyChanged();
}
}
public event PropertyChangedEventHandler PropertyChanged;
private void NotifyPropertyChanged([CallerMemberName] String propertyName = "")
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}