Wpf 文本框显示“;System.Windows.Controls.TextBox“;通过.lnk打开PS1文件时

Wpf 文本框显示“;System.Windows.Controls.TextBox“;通过.lnk打开PS1文件时,wpf,powershell,windows-forms-designer,Wpf,Powershell,Windows Forms Designer,我在WPF和powershell中使用XML作为gui模板制作了一个小应用程序。 当我用鼠标右键单击打开整个应用程序,并用powershell of打开它时,整个应用程序运行良好,即使我打开了一个我为它制作的.exe文件。 但当我试图用一个.lnk文件打开它时,它不会显示它的版本,而是显示“System.Windows.Controls.TextBox” 由于安全原因,我无法显示所有代码,但我可以在需要时进行协作 另外,我不经常在堆栈溢出上发表文章,如果我做错了什么,请告诉我 在XML中:

我在WPF和powershell中使用XML作为gui模板制作了一个小应用程序。 当我用鼠标右键单击打开整个应用程序,并用powershell of打开它时,整个应用程序运行良好,即使我打开了一个我为它制作的.exe文件。 但当我试图用一个.lnk文件打开它时,它不会显示它的版本,而是显示“System.Windows.Controls.TextBox”

由于安全原因,我无法显示所有代码,但我可以在需要时进行协作

另外,我不经常在堆栈溢出上发表文章,如果我做错了什么,请告诉我

在XML中:

[xml]$04Instellingen = @"
<Grid
    xmlns:Controls="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Height="470" Width="852">

    <Grid.Background>
        <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
            <GradientStop Color="#FFEEFAFF" Offset="1"/>
            <GradientStop Color="White" Offset="0.4"/>
        </LinearGradientBrush>
    </Grid.Background>
    <TabControl x:Name="tabControl" HorizontalAlignment="Left" Height="291" Margin="32,14,0,0" VerticalAlignment="Top" Width="801" Background="{x:Null}">
        <TabItem Header="Algemeen">
            <Grid>
                <Label x:Name="label1_Copy" Content="Benaming:" HorizontalAlignment="Left" Margin="5,47,0,0" VerticalAlignment="Top" Width="119"/>
                <Label x:Name="label1_Copy1" Content="Ip adres:" HorizontalAlignment="Left" Margin="146,47,0,0" VerticalAlignment="Top" Width="119"/>
                <TextBox x:Name="ipnaam1" HorizontalAlignment="Left" Height="23" Margin="10,77,0,0" TextWrapping="Wrap" Text="Server1" VerticalAlignment="Top" Width="120"/>
                <TextBox x:Name="ip1" HorizontalAlignment="Left" Height="23" Margin="150,77,0,0" TextWrapping="Wrap" Text="Server1 ip adres" VerticalAlignment="Top" Width="165"/>
                <TextBox x:Name="ipnaam2" HorizontalAlignment="Left" Height="23" Margin="10,110,0,0" TextWrapping="Wrap" Text="Server2" VerticalAlignment="Top" Width="120"/>
                <TextBox x:Name="ip2" HorizontalAlignment="Left" Height="23" Margin="150,110,0,0" TextWrapping="Wrap" Text="Server2 ip adres" VerticalAlignment="Top" Width="165"/>
                <TextBox x:Name="ipnaam3" HorizontalAlignment="Left" Height="23" Margin="10,144,0,0" TextWrapping="Wrap" Text="Server3" VerticalAlignment="Top" Width="120"/>
                <TextBox x:Name="ip3" HorizontalAlignment="Left" Height="23" Margin="150,144,0,0" TextWrapping="Wrap" Text="Server2 ip adres" VerticalAlignment="Top" Width="165"/>
                <Label x:Name="label5" Content="Stel hieronder de servernamen en ip andressen in die automatisch op conetiviteid worden getest." HorizontalAlignment="Left" Margin="5,13,0,0" VerticalAlignment="Top" Width="545"/>
            </Grid>
        </TabItem>
     #More code here but is irrelevant#
</Grid>
"@
$ipnaam1      = $AboutXaml.FindName("ipnaam1") 
$ipnaam1.Text = $global:ipnaam1

$ipnaam2      = $AboutXaml.FindName("ipnaam2") 
$ipnaam2.Text = $global:ipnaam2

$ipnaam3      = $AboutXaml.FindName("ipnaam3") 
$ipnaam3.Text = $global:ipnaam3

$ip1      = $AboutXaml.FindName("ip1") 
$ip1.Text = $global:ipadres1

$ip2      = $AboutXaml.FindName("ip2") 
$ip2.Text = $global:ipadres2

$ip3      = $AboutXaml.FindName("ip3") 
$ip3.Text = $global:ipadres3
function Import-Config {
    #If a config file exists for the current user in the expected location, it is imported
    #and values from the config file are placed into global variables
    if (Test-Path -Path "$loc\instellingen\Config.config") {
        try {
            #Imports the config file and saves it to variable $Config
            $Config = Import-Clixml -Path "$loc\instellingen\Config.config"
            
            #Creates global variables for each config property and sets their values
            $global:ServerBericht = $Config.ServerBericht
            $global:DownloadVan = $Config.DownloadVan
            $global:DownloadNaar = $Config.DownloadNaar
            $global:LogBestandLocatie = $Config.LogBestandLocatie
            $global:InfoTextElias = $Config.InfoTextElias
            $global:ipnaam1 = $Config.ipnaam1
            $global:ipnaam2 = $Config.ipnaam2
            $global:ipnaam3 = $Config.ipnaam3
            $global:ipadres1 = $Config.ipadres1
            $global:ipadres2 = $Config.ipadres2
            $global:ipadres3 = $Config.ipadres3
        }
        catch {
            [System.Windows.Forms.MessageBox]::Show("An error occurred importing your Config file. A new Config file will be generated for you. $_", 'Import Config Error', 'OK', 'Error')
            New-Config
        }
    } #end if config file exists
    else {
        New-Config
    }
} #end function Import-Config
从何处获得其价值:

[xml]$04Instellingen = @"
<Grid
    xmlns:Controls="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Height="470" Width="852">

    <Grid.Background>
        <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
            <GradientStop Color="#FFEEFAFF" Offset="1"/>
            <GradientStop Color="White" Offset="0.4"/>
        </LinearGradientBrush>
    </Grid.Background>
    <TabControl x:Name="tabControl" HorizontalAlignment="Left" Height="291" Margin="32,14,0,0" VerticalAlignment="Top" Width="801" Background="{x:Null}">
        <TabItem Header="Algemeen">
            <Grid>
                <Label x:Name="label1_Copy" Content="Benaming:" HorizontalAlignment="Left" Margin="5,47,0,0" VerticalAlignment="Top" Width="119"/>
                <Label x:Name="label1_Copy1" Content="Ip adres:" HorizontalAlignment="Left" Margin="146,47,0,0" VerticalAlignment="Top" Width="119"/>
                <TextBox x:Name="ipnaam1" HorizontalAlignment="Left" Height="23" Margin="10,77,0,0" TextWrapping="Wrap" Text="Server1" VerticalAlignment="Top" Width="120"/>
                <TextBox x:Name="ip1" HorizontalAlignment="Left" Height="23" Margin="150,77,0,0" TextWrapping="Wrap" Text="Server1 ip adres" VerticalAlignment="Top" Width="165"/>
                <TextBox x:Name="ipnaam2" HorizontalAlignment="Left" Height="23" Margin="10,110,0,0" TextWrapping="Wrap" Text="Server2" VerticalAlignment="Top" Width="120"/>
                <TextBox x:Name="ip2" HorizontalAlignment="Left" Height="23" Margin="150,110,0,0" TextWrapping="Wrap" Text="Server2 ip adres" VerticalAlignment="Top" Width="165"/>
                <TextBox x:Name="ipnaam3" HorizontalAlignment="Left" Height="23" Margin="10,144,0,0" TextWrapping="Wrap" Text="Server3" VerticalAlignment="Top" Width="120"/>
                <TextBox x:Name="ip3" HorizontalAlignment="Left" Height="23" Margin="150,144,0,0" TextWrapping="Wrap" Text="Server2 ip adres" VerticalAlignment="Top" Width="165"/>
                <Label x:Name="label5" Content="Stel hieronder de servernamen en ip andressen in die automatisch op conetiviteid worden getest." HorizontalAlignment="Left" Margin="5,13,0,0" VerticalAlignment="Top" Width="545"/>
            </Grid>
        </TabItem>
     #More code here but is irrelevant#
</Grid>
"@
$ipnaam1      = $AboutXaml.FindName("ipnaam1") 
$ipnaam1.Text = $global:ipnaam1

$ipnaam2      = $AboutXaml.FindName("ipnaam2") 
$ipnaam2.Text = $global:ipnaam2

$ipnaam3      = $AboutXaml.FindName("ipnaam3") 
$ipnaam3.Text = $global:ipnaam3

$ip1      = $AboutXaml.FindName("ip1") 
$ip1.Text = $global:ipadres1

$ip2      = $AboutXaml.FindName("ip2") 
$ip2.Text = $global:ipadres2

$ip3      = $AboutXaml.FindName("ip3") 
$ip3.Text = $global:ipadres3
function Import-Config {
    #If a config file exists for the current user in the expected location, it is imported
    #and values from the config file are placed into global variables
    if (Test-Path -Path "$loc\instellingen\Config.config") {
        try {
            #Imports the config file and saves it to variable $Config
            $Config = Import-Clixml -Path "$loc\instellingen\Config.config"
            
            #Creates global variables for each config property and sets their values
            $global:ServerBericht = $Config.ServerBericht
            $global:DownloadVan = $Config.DownloadVan
            $global:DownloadNaar = $Config.DownloadNaar
            $global:LogBestandLocatie = $Config.LogBestandLocatie
            $global:InfoTextElias = $Config.InfoTextElias
            $global:ipnaam1 = $Config.ipnaam1
            $global:ipnaam2 = $Config.ipnaam2
            $global:ipnaam3 = $Config.ipnaam3
            $global:ipadres1 = $Config.ipadres1
            $global:ipadres2 = $Config.ipadres2
            $global:ipadres3 = $Config.ipadres3
        }
        catch {
            [System.Windows.Forms.MessageBox]::Show("An error occurred importing your Config file. A new Config file will be generated for you. $_", 'Import Config Error', 'OK', 'Error')
            New-Config
        }
    } #end if config file exists
    else {
        New-Config
    }
} #end function Import-Config
.Config文件填充

<Objs Version="1.1.0.1" xmlns="http://schemas.microsoft.com/powershell/2004/04">
  <Obj RefId="0">
    <TN RefId="0">
      <T>System.Collections.Hashtable</T>
      <T>System.Object</T>
    </TN>
    <DCT>
      <En>
        <S N="Key">ipadres3</S>
        <S N="Value">127.0.0.1</S>
      </En>
      <En>
        <S N="Key">LogBestandLocatie</S>
        <S N="Value">C:\temp</S>
      </En>
      <En>
        <S N="Key">ipadres1</S>
        <S N="Value">127.0.0.1</S>
      </En>
      <En>
        <S N="Key">ipadres2</S>
        <S N="Value">127.0.0.1</S>
      </En>
      <En>
        <S N="Key">ServerBericht</S>
        <S N="Value">Er zijn geen netwerk berichten.</S>
      </En>
      <En>
        <S N="Key">DownloadNaar</S>
        <S N="Value">C:\maps</S>
      </En>
      <En>
        <S N="Key">ipnaam3</S>
        <S N="Value">Ongedefinieerd</S>
      </En>
      <En>
        <S N="Key">ipnaam1</S>
        <S N="Value">Ongedefinieerd</S>
      </En>
      <En>
        <S N="Key">InfoTextElias</S>
        <S N="Value">Als de app vast lijkt te lopen dan is deze druk aan het werk, Wees geduldig.  (Hier word aan gewerkt)</S>
      </En>
      <En>
        <S N="Key">DownloadVan</S>
        <S N="Value">\MAPS-HIER</S>
      </En>
      <En>
        <S N="Key">ipnaam2</S>
        <S N="Value">Ongedefinieerd</S>
      </En>
    </DCT>
  </Obj>
</Objs>

填充该值的代码在哪里?调试时,该值来自何处?用户界面的图片并不能告诉我们很多关于这个问题的信息。@artafact-如果你不能发布你的原始代码,你能创建一个你可以发布的“最小可复制示例”吗?(见附件)。没有一些示例代码,这个问题就没有什么可谈的了。@David我编辑了这篇文章,谢谢你的评论。@mclayton我编辑了这篇文章,谢谢你的评论。@Artafact-这更好,但代码中似乎有很多不相关的东西,这使得我们很难知道从哪里开始。如果您可以发布一个“最小的、可复制的示例”来演示特定的问题,而不是包括整个应用程序,这将非常有帮助(例如,从xaml中删除所有不相关的控件,并提供一个可剪切和可复制的脚本-我必须解决如何转换[xml]进入xaml窗口,以便使用
$AboutXaml=[System.Windows.Markup.XamlReader]::加载($reader)
,但您的代码可能正在执行一些不同的操作)。