使用XML PowerShell将WPF网格固定到任务栏

时间:2019-07-24 07:46:49

标签: wpf powershell

我尝试使用powershell(xml)创建wpf网格并将其固定到任务栏 没有成功

这是代码:

$IP = ((ipconfig) -match "IPv4").split(":")[1].trim()
# Add xml
$xmlcontent = '<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Name="window" WindowStyle="None" Height="40" Width="250"
ResizeMode="NoResize" ShowInTaskbar="false">
<Window.TaskbarItemInfo>
        <TaskbarItemInfo>
            <TaskbarItemInfo.ProgressValue></TaskbarItemInfo.ProgressValue>
        </TaskbarItemInfo>
    </Window.TaskbarItemInfo>
<Grid Name="grid" Height="40" Width="249" Background="#0f1317" >
    <Label Name="label" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" Content="info" Foreground="White" FontSize="15" FontFamily="ariel"/>
</Grid>
</Window>'

# "#0f1317" - Background Color Server
# "#13181e" - Background color Client

# Add the required assemblies 
Add-Type -AssemblyName PresentationFramework,System.Windows.Forms

# Add a super simple form that contains a just with text within a grid
[xml]$xaml =  $xmlcontent.Replace("info","$env:COMPUTERNAME - $IP")

# Turn the xaml into a form
$script:window = [Windows.Markup.XamlReader]::Load((New-Object System.Xml.XmlNodeReader $xaml))
$xaml.SelectNodes("//*[@Name]") | ForEach-Object { Set-Variable -Name ($_.Name) -Value $window.FindName($_.Name) -Scope Script }

# Double click the window
$window.Add_MouseDoubleClick({
    $window.Close() 
})


$window.Left = $([System.Windows.SystemParameters]::WorkArea.Width-503)
$window.Top = $([System.Windows.SystemParameters]::WorkArea.Height-0)
$window.Topmost = $true
$window.Focusable = $true
$window.ShowDialog() | Out-Null

预期:在任务栏上显示wpf网格,其中包含机器名称和IP地址
实际结果:错误

  

使用“ 1”参数调用“ Load”的异常:“ Set属性   'System.Windows.Shell.TaskbarItemInfo.ProgressValue'引发了   例外。“在行:28 char:1   + $ script:window = [Windows.Markup.XamlReader] :: Load((New-Object System ...   + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~       + CategoryInfo:未指定:(:) [],MethodInvocationException       + FullyQualifiedErrorId:XamlParseException使用“ 0”参数调用“ ShowDialog”的异常:“无法设置可见性或调用   窗口后的Show,ShowDialog或WindowInteropHelper.EnsureHandle   已关闭。“在线:41 char:1   + $ window.ShowDialog()|空空   + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~       + CategoryInfo:未指定:(:) [],MethodInvocationException       + FullyQualifiedErrorId:InvalidOperationException

0 个答案:

没有答案