【发布时间】:2012-02-13 08:27:16
【问题描述】:
我正在尝试在我的 Windows Phone (7.1) 应用程序中进行“类似 TreeView”的显示。
为此,我在Silverlight Toolkit 中使用了“ExpanderView”。
所以基本上,我的程序在 ExpanderViews 中添加 ExpanderViews 以创建树。
一切都很好,直到一个元素水平超出屏幕,它给了我一个异常“参数不正确”。在以下代码中的“Debugger.Break()”行上:
// Code to execute on Unhandled Exceptions
private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e)
{
if (System.Diagnostics.Debugger.IsAttached)
{
// An unhandled exception has occurred; break into the debugger
System.Diagnostics.Debugger.Break();
}
}
在 App.xaml.cs 下。
我假设元素没有正确初始化/加载,因为我之前使用相同的元素有过这个异常,我在没有完全加载父元素的情况下添加项目。
这是我的 XAML:
<Grid x:Name="LayoutRoot" Background="Transparent">
<Grid x:Name="ContentPanel" Margin="12,0,12,0"/>
</Grid>
<phone:PhoneApplicationPage.ApplicationBar>
<shell:ApplicationBar IsVisible="True" IsMenuEnabled="True">
<shell:ApplicationBarIconButton IconUri="/Images/Plus.png" Text="Add" Click="ApplicationBarIconButtonClick"/>
</shell:ApplicationBar>
</phone:PhoneApplicationPage.ApplicationBar>
这是背后的代码:
public MainPage()
{
InitializeComponent();
_lastView = new ExpanderView { Header = "Header", IsExpanded = true };
ContentPanel.Children.Add(_lastView);
}
private ExpanderView _lastView;
private void ApplicationBarIconButtonClick(object sender, System.EventArgs e)
{
var newItem = new ExpanderView {Header = "Header", IsExpanded = true};
_lastView.Items.Add(newItem);
_lastView = newItem;
}
下一次我单击应用程序栏按钮时(当下一个元素水平超出屏幕时),它给了我异常:
【问题讨论】:
-
什么异常?它出现在哪一行?
-
我在问题的第二段中提到过。
标签: windows-phone-7.1 silverlight-toolkit