I've ran into an issue while using WPF. When I open the window, I want it to open up on top of all other programs but I don't want it to remain always on top, just the initial opening. I know setting topmost to true will open up on top (which I have in the Xaml), but I can't seem to find a way to change it to false after it has opened.
This is a simple test function with a WPF window.
function foo{
#Load Assembly and Library
Add-Type -AssemblyName PresentationFramework
$inputXaml = @"
<Window x:Class="SharepointCreateOpportunity.completeWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:SharepointCreateOpportunity"
mc:Ignorable="d"
Title="Window Title" Height="250" MinHeight="250" MaxHeight="250" Width="500" MinWidth="500" MaxWidth="500" Topmost="True" WindowStartupLocation="CenterScreen" Background="Black" >
<Grid>
<Button Name="oKBtn" Content="OK" Margin="0,0,20,20" HorizontalAlignment="Right" VerticalAlignment="Bottom" Width="72" Height="23"/>
</Grid>
</Window>
"@
#Gets rid of elements from the Xaml so it can be converted
$inputXamlClean = $inputXaml -replace 'mc:Ignorable="d"','' -replace "x:N",'N' -replace 'x:Class=".*?"','' -replace 'd:DesignHeight="\d*?"','' -replace 'd:DesignWidth="\d*?"',''
[xml]$xaml = $inputXamlClean
#Creates the Window
$XMLReader = (New-Object System.Xml.XmlNodeReader $xaml)
$Window = [Windows.Markup.XamlReader]::Load($XMLReader)
#Creates variables for all the elements on the window
$xaml.SelectNodes("//*[@Name]") | %{Set-Variable -Name ($_.Name) -Value $Window.FindName($_.Name)}
#OK Button Action
$okBtn.Add_Click({
$Window.Close()
})
#Show window
$Window.ShowDialog()
}
foo