Click here to Skip to main content
15,907,392 members
Home / Discussions / C#
   

C#

 
GeneralRe: Copy the text of any windows anywhere Pin
OriginalGriff9-Oct-16 5:50
mveOriginalGriff9-Oct-16 5:50 
GeneralRe: Copy the text of any windows anywhere Pin
Daniyaltjm9-Oct-16 6:12
Daniyaltjm9-Oct-16 6:12 
GeneralRe: Copy the text of any windows anywhere Pin
OriginalGriff9-Oct-16 6:23
mveOriginalGriff9-Oct-16 6:23 
GeneralRe: Copy the text of any windows anywhere Pin
Daniyaltjm9-Oct-16 6:59
Daniyaltjm9-Oct-16 6:59 
GeneralRe: Copy the text of any windows anywhere Pin
NotPolitcallyCorrect9-Oct-16 5:50
NotPolitcallyCorrect9-Oct-16 5:50 
QuestionLine Control in C# 2005 ? Pin
Member 24584677-Oct-16 18:01
Member 24584677-Oct-16 18:01 
AnswerRe: Line Control in C# 2005 ? Pin
OriginalGriff7-Oct-16 19:39
mveOriginalGriff7-Oct-16 19:39 
AnswerRe: Line Control in C# 2005 ? Pin
Garth J Lancaster8-Oct-16 23:48
professionalGarth J Lancaster8-Oct-16 23:48 
QuestionStore persistent data Pin
sunsher6-Oct-16 15:25
sunsher6-Oct-16 15:25 
AnswerRe: Store persistent data Pin
Mycroft Holmes6-Oct-16 20:09
professionalMycroft Holmes6-Oct-16 20:09 
GeneralRe: Store persistent data Pin
OriginalGriff6-Oct-16 22:30
mveOriginalGriff6-Oct-16 22:30 
AnswerRe: Store persistent data Pin
NotPolitcallyCorrect6-Oct-16 23:45
NotPolitcallyCorrect6-Oct-16 23:45 
AnswerRe: Store persistent data Pin
ZurdoDev7-Oct-16 5:12
professionalZurdoDev7-Oct-16 5:12 
PraiseRe: Store persistent data Pin
Eddy Vluggen7-Oct-16 11:47
professionalEddy Vluggen7-Oct-16 11:47 
AnswerRe: Store persistent data Pin
Abhinav S7-Oct-16 20:23
Abhinav S7-Oct-16 20:23 
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? Pin
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 

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.