提问人:ExpertOnNothing 提问时间:11/4/2023 最后编辑:CraigExpertOnNothing 更新时间:11/6/2023 访问量:42
在 WPF 中引用来自模块的调用窗口 VB.net
Referencing Calling Window From Module in VB.net WPF
问:
我有一个带有一堆窗口的项目。我还有另一个窗口,用户可以在其中选择窗口的背景。我有一个模块,我想用它来设置实际的图像。这样一来,我就不需要在每个窗口上都写一大堆代码了......只有一行。
modDothing.setthewallpaper(Me)
但这是行不通的。它在我的模块中告诉我窗口未定义。
我已经注释了我尝试过的一些东西,但它们都不起作用——否则我就不会在这里了。我确信我在做一些愚蠢的事情。这是我用 (Me) 调用子程序的方式吗?感谢您对此的任何帮助
Module modDoThings
Public Sub setthewallpaper(ByVal window3 As Window)
'MsgBox(window3.GetType.Name)
'Application.Current.Windows.OfType(Of window3)().First().Close()
Dim theWindow As Window = TryCast(window3, Window)
Dim ih As New imageHolder
Dim finalImage As Image = New Image()
finalImage.Width = 380
finalImage.Height = 300
finalImage.Margin = New Thickness(5)
Dim logo As BitmapImage = New BitmapImage()
logo.BeginInit()
logo.UriSource = New Uri(System.AppDomain.CurrentDomain.BaseDirectory & "images\myWalls\" & My.Settings.currentWall)
logo.EndInit()
ImageBehavior.SetAnimatedSource(theWindow.WallBackground, logo)
ImageBehavior.SetRepeatBehavior(theWindow.WallBackground, RepeatBehavior.Forever)
theWindow.WallBackground.Source = logo
'Dim targetWindow = TryCast(Application.Current.Windows.Cast(Of Window)().FirstOrDefault(Function(window) TypeOf window Is theWindow), theWindow)
'targetWindow.WallBackground.Source = logo
'Application.Current.Windows.OfType(Of window3)().First().WallBackground.Source = logo
End Sub
End Module
答: 暂无答案
评论
theWindow
Window
WallBackground
window3
Window
Window
TryCast
DirectCast
Window
Window