Click here to Skip to main content
15,887,135 members
Home / Discussions / C#
   

C#

 
GeneralRe: Store persistent data Pin
sunsher9-Oct-16 16:26
sunsher9-Oct-16 16:26 
GeneralRe: Store persistent data Pin
Mycroft Holmes9-Oct-16 17:24
professionalMycroft Holmes9-Oct-16 17:24 
GeneralRe: Store persistent data Pin
sunsher10-Oct-16 0:16
sunsher10-Oct-16 0:16 
GeneralRe: Store persistent data Pin
Mycroft Holmes10-Oct-16 12:37
professionalMycroft Holmes10-Oct-16 12:37 
QuestionExecuting PS1 file to perform a task in Exchange Pin
choppol6-Oct-16 12:29
choppol6-Oct-16 12:29 
AnswerRe: Executing PS1 file to perform a task in Exchange Pin
Eddy Vluggen7-Oct-16 11:51
professionalEddy Vluggen7-Oct-16 11:51 
QuestionCan someone explain this WPF oddity? Pin
Foothill6-Oct-16 9:47
professionalFoothill6-Oct-16 9:47 
AnswerRe: Can someone explain this WPF oddity? PinPopular
Richard Deeming6-Oct-16 11:44
mveRichard Deeming6-Oct-16 11:44 
The default style for the TextBox control sets the background brush to:
XML
<Setter Property="Panel.Background">
<Setter.Value>
    <DynamicResource ResourceKey="{x:Static SystemColors.WindowBrushKey}" />
</Setter.Value>
</Setter>

(I couldn't find an official source, but you can view the default styles using Style Snooper[^].)

That configures the background to use the SystemColors.WindowBrush, and to dynamically update whenever the Windows colour settings are changed.

The WindowBrush property calls the MakeBrush method[^], which explicitly freezes the brush:
C#
private static SolidColorBrush MakeBrush(CacheSlot slot)
{
    SolidColorBrush brush;
    
    lock (_brushCacheValid)
    {
        if (!_brushCacheValid[(int)slot])
        {
            brush = new SolidColorBrush(GetSystemColor(slot));
            brush.Freeze();
            
            _brushCache[(int)slot] = brush;
            _brushCacheValid[(int)slot] = true;
        }
        else
        {
            brush = _brushCache[(int)slot];
        }
    }
    
    return brush;
}

When you try to animate that brush from the code-behind, you then get an error because it has been frozen: Freezable Objects Overview[^]

With your second code block, you've set the background to a new SolidColorBrush, which hasn't been frozen. The animation then works as expected. You could also use:
C#
private void FlashRequiredTextBox(TextBox target)
{
    ColorAnimation flash = ...;
    if (target.Background.IsFrozen) target.Background = target.Background.Clone();
    target.Background.BeginAnimation(SolidColorBrush.ColorProperty, flash);
}


As far as I can tell, when you configure the animation in the XAML markup, the system ensures that the background brush is not frozen. When you configure the animation from the code-behind, that check is left up to you.



"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer


GeneralRe: Can someone explain this WPF oddity? Pin
Mycroft Holmes6-Oct-16 12:41
professionalMycroft Holmes6-Oct-16 12:41 
GeneralRe: Can someone explain this WPF oddity? Pin
Foothill7-Oct-16 3:15
professionalFoothill7-Oct-16 3:15 
QuestionEventRecord's FormatDescription() is super slow Pin
_PitrakSarkar_4-Oct-16 20:05
_PitrakSarkar_4-Oct-16 20:05 
AnswerRe: EventRecord's FormatDescription() is super slow Pin
Pete O'Hanlon4-Oct-16 23:29
mvePete O'Hanlon4-Oct-16 23:29 
GeneralRe: EventRecord's FormatDescription() is super slow Pin
_PitrakSarkar_5-Oct-16 0:07
_PitrakSarkar_5-Oct-16 0:07 
GeneralRe: EventRecord's FormatDescription() is super slow Pin
Lucas Alvarez Lacasa21-Nov-18 8:10
Lucas Alvarez Lacasa21-Nov-18 8:10 
QuestionC# to C++ SEND AND RECIEVED Pin
Jarlo Belledo4-Oct-16 2:14
Jarlo Belledo4-Oct-16 2:14 
AnswerRe: C# to C++ SEND AND RECIEVED Pin
OriginalGriff4-Oct-16 2:28
mveOriginalGriff4-Oct-16 2:28 
AnswerRe: C# to C++ SEND AND RECIEVED Pin
NotPolitcallyCorrect4-Oct-16 2:45
NotPolitcallyCorrect4-Oct-16 2:45 
AnswerRe: C# to C++ SEND AND RECIEVED Pin
Eddy Vluggen4-Oct-16 3:01
professionalEddy Vluggen4-Oct-16 3:01 
AnswerRe: C# to C++ SEND AND RECIEVED Pin
Pete O'Hanlon4-Oct-16 3:04
mvePete O'Hanlon4-Oct-16 3:04 
GeneralRe: C# to C++ SEND AND RECIEVED PinPopular
Mycroft Holmes4-Oct-16 12:50
professionalMycroft Holmes4-Oct-16 12:50 
QuestionRunning Powershell scripts in C# fails/no effect Pin
me@dagsunde.com3-Oct-16 22:35
professionalme@dagsunde.com3-Oct-16 22:35 
AnswerRe: Running Powershell scripts in C# fails/no effect Pin
Pete O'Hanlon3-Oct-16 23:44
mvePete O'Hanlon3-Oct-16 23:44 
GeneralRe: Running Powershell scripts in C# fails/no effect Pin
me@dagsunde.com4-Oct-16 0:20
professionalme@dagsunde.com4-Oct-16 0:20 
GeneralRe: Running Powershell scripts in C# fails/no effect Pin
me@dagsunde.com3-Oct-16 23:52
professionalme@dagsunde.com3-Oct-16 23:52 
GeneralRe: Running Powershell scripts in C# fails/no effect Pin
Pete O'Hanlon4-Oct-16 0:34
mvePete O'Hanlon4-Oct-16 0:34 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.