问题
I'm in the process of writing a small application in Powershell making use of xaml gui. THe application works fine on Windows 7 and Windows Server 2012 at work, but on my home desktop, which runs on Windows 8 it throws an exception. After debugging a bit, I discovered the piece of xaml which makes the script crash.
[xml]$Xaml = @'
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Windows Monitoring Framework" WindowStartupLocation="CenterScreen" Height="386" MinHeight="386" MaxHeight="400" Width="738" MinWidth="750" MaxWidth="750">
<Grid Margin="0,0,2,0">
<TabControl Name="WmfTabControl">
<TabItem Name="TabInfo" Header="Info">
<Grid Margin="0,0,-1,0">
<Label Name="lblInfoHostname" Content="Hostname" Height="25" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" VerticalAlignment="Top" HorizontalAlignment="Stretch" Margin="0,-1,0,0" Foreground="#FFFFFF" Background="#FF2E78E4" FontWeight="Bold" FontSize="14"/>
<Label Content="Recent Alerts" HorizontalAlignment="Left" Margin="0,26,0,0" VerticalAlignment="Top" Height="24" Width="113" Background="#FF2E78E4" Foreground="#FFFFFF" FontSize="11" FontWeight="Bold"/>
<ListView Name="lvRecentAlert" Margin="0,50,0,159">
<ListView.View>
<GridView>
<GridViewColumn Header="Date" Width="80"/>
<GridViewColumn Header="Service" Width="120"/>
<GridViewColumn Header="Alert" Width="300"/>
</GridView>
</ListView.View>
</ListView>
</Grid>
</TabItem>
</TabControl>
</Grid>
</Window>
'@
$Reader=(New-Object System.Xml.XmlNodeReader $Xaml)
$Form=[Windows.Markup.XamlReader]::Load( $Reader )
$Form.ShowDialog() | out-null
When I leave the part
<GridViewColumn Header="Date" Width="80"/>
<GridViewColumn Header="Service" Width="120"/>
<GridViewColumn Header="Alert" Width="300"/>
out the xaml, it works again.
The error thrown on my Windows 8 is:
Exception calling "ShowDialog" with "0" argument(s): "The file exists.
"
At C:\Users\Willem\Dropbox\Scripts\Powershell\Tools\Windows_Monitoring_Framework\Windows_Monitoring_Framework.ps1:465 char:1
+ $Form.ShowDialog() | out-null
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : IOException
I've been looking for hours what the issue might be, but I'm kind of stuck. As I would like to continue working on the script at home, I would be very thankful if someone would know what the issue might be.
Grtz
Willem
回答1:
Well, seem I managed to solve this by running an extensive ccleaner. THere must have been something ugly on my system. CHeerz :)
来源:https://stackoverflow.com/questions/28887207/showdialog-xaml-exception-with-listview-on-windows-8-only