如何使用2个窗口和.Show()使Add_PreviewMouseDown工作?

时间:2019-07-05 10:13:10

标签: wpf powershell xaml

我有一个带有主窗口的程序(powershell wpf / xaml)。该程序会检查文件并打开第二个窗口,如果缺少某些内容,则必须具有指向该文件夹的链接,为此我使用了.Add_PreviewMouseDown({ })。那行得通,但是如果我进行第二次检查,则窗口2会获得与窗口3相同的“文件夹链接”。如何使它起作用,窗口2的链接不会更新?

我已经尝试获取动态标签名称和PreviewMouseDown,但这还不够。


$Script:WindowNumber += 1
$WindowName = "Win$WindowNumber"

$CEMessage = '<Label Name="CEFout' + $WindowNumber + '"  HorizontalAlignment="Left" Margin="30,288,0,0" VerticalAlignment="Top" Width="142" FontSize="14" ToolTip="Fileserver Folder" >
                    <Hyperlink NavigateUri="Bureaublad\Machine Folder">&#10799; CE:</Hyperlink>
             </Label>'

New-Variable -Name "BijlagenWPF$WindowNumber" -Value ($BijlagenWPF = @"
<Window 
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        Title="Bijlagen" Height="420" Width="250" Icon="$Icon" ResizeMode="NoResize" ShowInTaskbar="True">

    <Grid HorizontalAlignment="Center" Margin="0,0,0,0" Width="240">

        $CEMessage

    </Grid>
</Window>
"@ -as [XML])

$NR2=(New-Object System.Xml.XmlNodeReader (Get-Variable | Where-Object Name -eq "BijlagenWPF$WindowNumber").Value)
New-Variable -Name $WindowName -Value ([Windows.Markup.XamlReader]::Load( $NR2 ))

$BijlagenWPF.SelectNodes("//*[@*[contains(translate(name(.),'n','N'),'Name')]]")  | ForEach-Object { 
    New-Variable -Name $_.Name -Value (Get-Variable | Where-Object Name -eq $WindowName).Value.FindName($_.Name) -Force 
}

(Get-Variable | Where-Object Name -eq "CEFout$WindowNumber").Value.Add_PreviewMouseDown({[system.Diagnostics.Process]::start("$Desktop\$Machine\Fileserver\manual\bijlagen")})

(Get-Variable | Where-Object Name -eq $WindowName).Value.Show()

This is a screenshot of the 2 windows with opened link. Now the link in the first window (2532-163) is the same as the second window (2532-164). But has to be 2532-163 folder

0 个答案:

没有答案