【发布时间】:2017-08-05 12:58:24
【问题描述】:
我正在尝试将 XAML 代码转换为 Visual Studio 中 WPF 项目的 XML 代码,以便我可以更轻松地使用 PowerShell。但我收到以下错误。
代码:
[xml]$XAML = "@
<Window
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:Controler"
Title="Ahmad's PowerShell Utitlity" Height="350" Width="525">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="36*"/>
<ColumnDefinition Width="430*"/>
<ColumnDefinition Width="51*"/>
</Grid.ColumnDefinitions>
<GroupBox Header="Actions" HorizontalAlignment="Left" Height="285" Margin="18,19,0,0" VerticalAlignment="Top" Width="78" Grid.ColumnSpan="2"/>
<GroupBox Header="Computer Name" HorizontalAlignment="Left" Height="60" Margin="73,30,0,0" VerticalAlignment="Top" Width="376" Grid.Column="1" Grid.ColumnSpan="2"/>
<GroupBox Header="Results" HorizontalAlignment="Left" Height="203" Margin="73,101,0,0" VerticalAlignment="Top" Width="376" Grid.Column="1" Grid.ColumnSpan="2"/>
<StackPanel HorizontalAlignment="Right" Height="258" VerticalAlignment="Top" Width="64" Margin="0,46,375.756,0" Grid.ColumnSpan="2">
<Button Content="Services"/>
<Button Content="Process"/>
<Button Content="Drives" Click="Button_Click"/>
</StackPanel>
</Grid>
</Window>
"@
错误: 错误 令牌“[xml]$XAML = “@”是意外的。
错误'根级别的数据无效。第 1 行,位置 1。 XML 无效。
严重性代码 描述 项目文件行抑制状态 错误未定义的 CLR 命名空间。 “clr-namespace” URI 引用了无法找到的命名空间“Controler”。 严重性代码 描述 项目文件行抑制状态 错误令牌““@”是意外的。
【问题讨论】:
-
PowerTip: Use Here-Strings with PowerShell:
[xml]$XAML = @"而不是[xml]$XAML = "@
标签: xml wpf visual-studio powershell xaml