在1个解决方案中更新其他项目的UI

时间:2017-04-08 08:39:16

标签: wpf vb.net

是否可以在同一解决方案中使用Project2更新Project1的UI?我设法使用Project2运行并访问Project1中的类,但不是控件。到目前为止,我尝试了ff:

在Project1 Loaded()事件中:

    Dim newMenu As MenuItem
    newMenu = New MenuItem()
    newMenu.Header = "This is new"
    newMenu.Tag = "1"
    AddHandler newMenu.Click, New EventHandler(AddressOf menuClick)
    myMenu.Items.Add(newMenu)

menuClick()

Private Sub menuClick(sender As Object, e As RoutedEventArgs)
    If sender.Tag = "1" Then
        Dim progTag As Integer = Integer.Parse(sender.Tag)
        Dim restriction = (From x In localdb.Restrictions
                           Where x.Username = "oliverc" Where x.Program_ID = progTag
                           Select x.Module_ID)

        If restriction.Count > 0 Then
            For Each ListItem In restriction.ToList
                restrict.Add(New Project2.Restrictions() With {.RestrictionTag = ListItem.ToString})
            Next
        End If

        For Each ListItem In restrict
            MessageBox.Show(ListItem.RestrictionTag(0))
        Next



        Dim frm As Project2.MainWindow = New Project2.MainWindow()
        frm.ShowDialog()

    End If
End Sub

在Project2中Loaded()

 For Each ListItem In listOfRestriction
        Select Case ListItem.ToString
            Case "1"
                btn_addRegion.IsEnabled = False
        End Select
        MessageBox.Show(ListItem.ToString)
    Next

1 个答案:

答案 0 :(得分:0)

简短回答:否。

答案很长:

每个项目都将编译为独立的.exe或.dll。即使您尝试这样做的当前方式是可能的,Project2 - exe也不可能知道它应该修改的Project1哪个实例(如果有的话)。

为了与其他exe进行通信,您需要实现Interprocess communication。然后,只要Project1被告知,就必须Project2 自行更改

您可以使用某些类型的IPC: