the code of xaml:
<pre><Window x:Class="WpfTopmost.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
WindowStyle="None"
AllowsTransparency="True"
Loaded="Window_Loaded"
Background="Transparent"
Title="MainWindow" Height="130" Width="130">
<Grid Background="Transparent">
<Ellipse Fill="Transparent" Stroke="Green" StrokeThickness="3"></Ellipse>
</Grid>
</Window>
the code of xaml.cs:
private void Window_Loaded(object sender, RoutedEventArgs e)
{
try
{
Thread globalThread = new Thread((ThreadStart)delegate
{
MouseStopTimeSpan();
});
globalThread.IsBackground = true;
globalThread.Start();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
private void MouseStopTimeSpan()
{
try
{
while (true)
{
try
{
Thread.Sleep(2);
lock (_thisLock)
{
this.Dispatcher.Invoke(new Action(() =>
{
this.Topmost = false;
this.Topmost = true;
}), null);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}