Inverting color depending on the background windows and desktop
I have a transparent wpf window ( WindowStyle="None"
) with black label. I need to make that label change its color dynamically, depending on 开发者_运维百科the background of the content below my window (other windows, desktop), so it will be always visible and contrast.
How can this be implemented? Do I need to make a screenshot and read color values from there or there is some way to do it with WPF tools?
Will it be more difficult if label has a gradient?
I don't suppose it's an option to make the text of the label have a contrasting outline around the letters?
You can sort of do this with a drop shadow type effect that uses a contrasting color to make (for example), black text have a white border.
<Page
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Grid Background="Black">
<TextBlock Text="This is some text" FontSize="24" Margin="30" Foreground="Black" FontWeight="Bold">
<TextBlock.Effect>
<DropShadowEffect ShadowDepth="0" Opacity="1" BlurRadius="4" Color="White"/>
</TextBlock.Effect>
</TextBlock>
</Grid>
</Page>
The drop shadow isn't exactly well defined, but something like this is very visible. The code's not pretty, but it works. Maybe someone else has a better idea how to get this to work using a built in effect or something.
<Page
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Grid Background="Black">
<TextBlock Text="This is some text" FontWeight="Bold" FontSize="24" Margin="28,30" Foreground="White" />
<TextBlock Text="This is some text" FontWeight="Bold" FontSize="24" Margin="32,30" Foreground="White" />
<TextBlock Text="This is some text" FontWeight="Bold" FontSize="24" Margin="30,28" Foreground="White" />
<TextBlock Text="This is some text" FontWeight="Bold" FontSize="24" Margin="30,32" Foreground="White" />
<TextBlock Text="This is some text" FontWeight="Bold" FontSize="24" Margin="28,28" Foreground="White" />
<TextBlock Text="This is some text" FontWeight="Bold" FontSize="24" Margin="32,32" Foreground="White" />
<TextBlock Text="This is some text" FontWeight="Bold" FontSize="24" Margin="32,28" Foreground="White" />
<TextBlock Text="This is some text" FontWeight="Bold" FontSize="24" Margin="28,32" Foreground="White" />
<TextBlock Text="This is some text" FontWeight="Bold" FontSize="24" Margin="30" Foreground="Black"></TextBlock>
</Grid>
</Page>
EDIT
MSDN has info on creating outlined text using WPFs ability to convert text to geometries, or to simply creating formatted text.
精彩评论