在WPF中,如何从CodeBehind访问WrapPanel
我在XAML中有一个定义如下的WrapPanel在WPF中,如何从CodeBehind访问WrapPanel,wpf,vb.net,wpf-controls,runtime-error,Wpf,Vb.net,Wpf Controls,Runtime Error,我在XAML中有一个定义如下的WrapPanel <Page x:Class="SelectImages" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-com
<Page x:Class="SelectImages"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="320" d:DesignWidth="480"
Title="Select Images">
<Grid>
<WrapPanel Name="MyImagePanel" Width="Auto" Height="Auto" Margin="10,50,10,10" ScrollViewer.HorizontalScrollBarVisibility="Disabled" ScrollViewer.VerticalScrollBarVisibility="Auto" Orientation="Horizontal">
</WrapPanel>
</Grid>
</Page>
谁能告诉我我做错了什么吗?我正在使用
Dim SelectImages显示为新的SelectImages(FolderPath,SelectedProductID)
Me.NavigationService.Navigate(选择ImageSpage)
构造函数似乎不会自动初始化组件。在我的页面上向构造函数添加了
InitializeComponent()
,现在一切正常。MyImagePanel
将null
直到调用InitializeComponent()
之后。如果Image
是null
或者不是FileSystemInfo
,那么Image-As-FileSystemInfo
可能是null
。找出什么是null
。或者发布异常堆栈。查看调用堆栈以查看空异常的位置。MyImagePanel
为空。我还在同一页上测试了其他控件。所有这些控件都返回相同的错误,并且所有控件在运行时都为null,即使它们在XAML中声明。您能给我们提供更多关于您背后代码的信息吗,一定有什么地方出错了,它们不应该为null。我想我明白了。。。我正在使用…导航到此页面Dim SelectImagesPage作为新的SelectImages(FolderPath,SelectedProductID)
\uCode>Me.NavigationService.Navigate(SelectImagesPage)构造函数似乎不会自动初始化组件。在我的页面上的构造函数中添加了InitializeComponent()
,现在一切正常。
Private Sub AddImageToPanel(Image As FileSystemInfo)
MyImagePanel.Children.Add(NewPicture(Image))
End Sub