Change foreground color of Expander Header after modifying one item
<p>Hy everyone,</p>

<p>i have a problem to get the foreground color of an expander Header changed after modifying an item of that expander.</p>

<p>Here is my WPF snippet, which i already have:</p>

<pre><code>&lt;GroupStyle&gt;
    &lt;GroupStyle.ContainerStyle&gt;
        &lt;Style TargetType="{x:Type GroupItem}"&gt;
            &lt;Setter Property="Margin" Value="0"/&gt;
            &lt;Setter Property="Template"&gt;
                &lt;Setter.Value&gt;
                    &lt;ControlTemplate TargetType="{x:Type GroupItem}"&gt;
                        &lt;Expander Margin="10,0,0,0" IsExpanded="True"
                                  BorderBrush="{Binding ., Converter={StaticResource BackgroundHeader}}"&gt;
                            &lt;Expander.Background&gt;
                                &lt;Binding Path="." Converter="{StaticResource BackgroundHeader}" /&gt;
                            &lt;/Expander.Background&gt;
                            &lt;Expander.Header &gt;
                                &lt;DockPanel Background="{Binding .,Converter={StaticResource BackgroundHeader}}"&gt;
                                    &lt;TextBlock FontWeight="Bold" Text="{Binding Path=Name, UpdateSourceTrigger=PropertyChanged}" 
                                               Foreground="{Binding ., Converter={StaticResource ForegroundHeader}}" 
                                               Margin="5,0,0,0"/&gt;
                                &lt;/DockPanel&gt;
                            &lt;/Expander.Header&gt;
                            &lt;Expander.Content&gt;
                                &lt;ItemsPresenter /&gt;
                            &lt;/Expander.Content&gt;
                        &lt;/Expander&gt;
                    &lt;/ControlTemplate&gt;
                &lt;/Setter.Value&gt;
            &lt;/Setter&gt;
        &lt;/Style&gt;
    &lt;/GroupStyle.ContainerStyle&gt;
&lt;/GroupStyle&gt;
</code></pre>

<p>I have already tried to Refresh my ListCollectionView after changing values, but the performance is really bad.</p>

<pre><code>MyListCollectionView.Refresh();
</code></pre>

<p>Thanks for any help...</p>

<p><strong>UPDATE:</strong>
Here is my WPF Snippet within the <code>GroupStyle</code> is defined:</p>

<pre><code>&lt;DataGrid x:Name="DataGridItemList" Grid.Row="1" ItemsSource="{Binding Path= CurrentWorkItemList}"
          SelectedItem="{Binding Path= CurrentSelectedItem}" AutoGenerateColumns="False" CanUserAddRows="False"&gt;
    &lt;DataGrid.Columns&gt;
        &lt;DataGridTemplateColumn&gt;
            &lt;.../&gt;
        &lt;/DataGridTemplateColumn&gt;
        &lt;DataGridTemplateColumn x:Name="SelectedCol" Header=" " CanUserResize="False"&gt;
            &lt;DataGridTemplateColumn.CellTemplate &gt;
                &lt;DataTemplate&gt;
                    &lt;CheckBox x:Name="ckbIsSelected" Click="CkbIsSelected_OnClick" IsChecked="{Binding Path = IsSelected, UpdateSourceTrigger=PropertyChanged}"  HorizontalAlignment="Center"
                              IsEnabled="{Binding Path = Mandatory, Converter={StaticResource InvertBoolean}}"/&gt;
                &lt;/DataTemplate&gt;
            &lt;/DataGridTemplateColumn.CellTemplate&gt;
        &lt;/DataGridTemplateColumn&gt;
        &lt;DataGridTemplateColumn&gt;
            &lt;.../&gt;
        &lt;/DataGridTemplateColumn&gt;
    &lt;/DataGrid.Columns&gt;
    &lt;DataGrid.GroupStyle&gt;
        &lt;!-- Style for groups at top level. --&gt;
        &lt;GroupStyle&gt;
            &lt;GroupStyle.ContainerStyle&gt;
                &lt;Style TargetType="{x:Type GroupItem}"&gt;
                    &lt;Setter Property="Margin" Value="0"/&gt;
                    &lt;Setter Property="Template"&gt;
                        &lt;Setter.Value&gt;
                            &lt;ControlTemplate TargetType="{x:Type GroupItem}"&gt;
                                &lt;Expander Margin="10,0,0,0" IsExpanded="True"
                                          BorderBrush="{Binding ., Converter={StaticResource BackgroundHeader}}"&gt;
                                    &lt;Expander.Background&gt;
                                        &lt;Binding Path="." Converter="{StaticResource BackgroundHeader}" /&gt;
                                    &lt;/Expander.Background&gt;
                                    &lt;Expander.Header &gt;
                                        &lt;DockPanel Background="{Binding .,Converter={StaticResource BackgroundHeader}}"&gt;
                                            &lt;TextBlock FontWeight="Bold" Text="{Binding Path=Name, UpdateSourceTrigger=PropertyChanged}" 
                                                       Foreground="{Binding ., Converter={StaticResource ForegroundHeader}}" 
                                                       Margin="5,0,0,0"/&gt;
                                        &lt;/DockPanel&gt;
                                    &lt;/Expander.Header&gt;
                                    &lt;Expander.Content&gt;
                                        &lt;ItemsPresenter /&gt;
                                    &lt;/Expander.Content&gt;
                                &lt;/Expander&gt;
                            &lt;/ControlTemplate&gt;
                        &lt;/Setter.Value&gt;
                    &lt;/Setter&gt;
                &lt;/Style&gt;
            &lt;/GroupStyle.ContainerStyle&gt;
        &lt;/GroupStyle&gt;
    &lt;/DataGrid.GroupStyle&gt;
    &lt;DataGrid.RowStyle&gt;
        &lt;Style TargetType="DataGridRow"&gt;
            &lt;Setter Property="Foreground" Value="Black" /&gt;
            &lt;Setter Property="Background" Value="White" /&gt;
        &lt;/Style&gt;
    &lt;/DataGrid.RowStyle&gt;
&lt;/DataGrid&gt;
</code></pre>

<p>...and the ViewModel for this View:</p>

<pre><code> public class ViewModel : INotifyPropertyChanged
    {
        public ViewModel()
        {
            ...
        }


        #region Properties

        private ListCollectionView _currentWorkItemList;

        public ListCollectionView CurrentWorkItemList
        {
            get { return _currentWorkItemList; }
            set
            {
                _currentWorkItemList = value;
                OnPropertyChanged("CurrentWorkItemList");
            }
        }

        private MyClass _CurrentSelectedItem;

        public MyClass CurrentSelectedItem
        {
            get { return _CurrentSelectedItem; }
            set
            {
                var saved = CheckChangesAndSaveItem(_CurrentSelectedItem);
                _CurrentSelectedItem = value;
                if (_CurrentSelectedItem != null)
                {
                    SetCurrentSelectedItemToCache(_CurrentSelectedItem);
                }
                OnPropertyChanged("CurrentSelectedItem");
            }
        }


        private MyClass _selectedItemCache;

        public MyClass SelectedItemCache
        {
            get { return _selectedItemCache; }
            set
            {
                _selectedItemCache = value;
                OnPropertyChanged("SelectedItemCache");
            }
        }

        #endregion


        #region Public Functions/Commands

        public void InitViewModel()
        {
            using (new WaitCursor())
            {
                CurrentWorkItemList = new ListCollectionView(...);
                if (CurrentWorkItemList.GroupDescriptions != null)
                {
                    CurrentWorkItemList.GroupDescriptions.Add(new PropertyGroupDescription("Group1"));
                    CurrentWorkItemList.GroupDescriptions.Add(new PropertyGroupDescription("Group2"));
                }
            }
        }


        public void CheckSaveAndCloneCurrentItem()
        {
            CheckSaveAndCloneCurrentItem(_CurrentSelectedItem);
        }

        #endregion



        #region Internal Functions



        private void CheckSaveAndCloneCurrentItem(MyClass currentItem)
        {
            var saved = CheckChangesAndSaveItem(currentItem);

            SetCurrentSelectedItemToCache(currentItem);
        }


        private void SetCurrentSelectedItemToCache(MyClass currentItem)
        {
            if (currentItem != null)
            {
                SelectedItemCache = currentItem.Clone();
            }
        }

        private bool CheckChangesAndSaveItem(MyClass currentItem)
        {
            var eItemIsSelected = ViewModels.DataAdapter.GetWorkItem().IsSelected;
            if (currentItem.IsSelected != SelectedItemCache.IsSelected || SelectedItemCache == null ||
                (currentItem.IsSelected != eItemIsSelected))
            {
                currentItem.Group1 = currentItem.Group1.ToString();
                ViewModels.DataAdapter.SaveAllListItem(currentItem);
                return true;
            }
            return false;
        }

        #endregion


        #region INotifyPropertyChanged

        public event PropertyChangedEventHandler PropertyChanged;
        private void OnPropertyChanged(string name)
        {
            if (PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs(name));
        }

        #endregion

    }
</code></pre>