频繁选择不同的组合框项导致winrt手机应用程序崩溃
本文关键字:winrt 手机 崩溃 应用程序 选择 组合 | 更新日期: 2023-09-27 18:04:32
我的应用程序崩溃了,所以我做了这个示例应用程序,这个也崩溃了。
xaml:
<Grid>
<StackPanel Grid.Row="0" Orientation="Vertical" >
<StackPanel Orientation="Horizontal">
<TextBlock x:Uid="EmirateTextBlock" />
</StackPanel>
<ComboBox PickerFlyoutBase.Title=" " Name="EmirateComboBox" x:Uid="EmirateComboBox" PlaceholderText="" DisplayMemberPath="vcPlateSource" />
<StackPanel Orientation="Horizontal">
<TextBlock x:Uid="CategoryTextBlock" />
</StackPanel>
<ComboBox PickerFlyoutBase.Title=" " Name="CategoryComboBox" x:Uid="CategoryComboBox" PlaceholderText="" DisplayMemberPath="vcPlateCateg" />
</StackPanel>
</Grid>
</Page>
cs文件:
public sealed partial class MainPage : Page
{
public MainPage()
{
this.InitializeComponent();
PopulateComboBox();
this.NavigationCacheMode = NavigationCacheMode.Required;
}
/// <summary>
/// Invoked when this page is about to be displayed in a Frame.
/// </summary>
/// <param name="e">Event data that describes how this page was reached.
/// This parameter is typically used to configure the page.</param>
protected override void OnNavigatedTo(NavigationEventArgs e)
{
// TODO: Prepare page for display here.
// TODO: If your application contains multiple pages, ensure that you are
// handling the hardware Back button by registering for the
// Windows.Phone.UI.Input.HardwareButtons.BackPressed event.
// If you are using the NavigationHelper provided by some templates,
// this event is handled for you.
}
public class stbPlateSource
{
public int tiPlateSourceId { get; set; }
public string cCountryCode { get; set; }
public string vcPlateSourceDesc { get; set; }
public string vcPlateSource
{
get
{
if (!IsEnglish)
{
return nvcPlateSourceArbDesc;
}
else
{
return vcPlateSourceDesc;
}
}
}
public static bool IsEnglish { get; set; }
public string nvcPlateSourceArbDesc { get; set; }
public int tiDisplayOrder { get; set; }
}
public class stbPlateCateg
{
public int Id { get; set; }
public int tiPlateCategId { get; set; }
public int tiPlateSourceId { get; set; }
public string vcPlateCategDesc { get; set; }
public string nvcPlateCategArbDesc { get; set; }
public static bool IsEnglish { get; set; }
public string vcPlateCateg
{
get
{
if (!IsEnglish)
{
return this.nvcPlateCategArbDesc;
}
else
{
return this.vcPlateCategDesc;
}
}
}
public stbPlateCateg() { }
}
private void PopulateComboBox()
{
// Step1
List<stbPlateSource> Emirates = new List<stbPlateSource>();
for (int i = 0; i < 250; i++)
{
Emirates.Add(new stbPlateSource() {
cCountryCode = "05" + i,
tiDisplayOrder = i+1,
tiPlateSourceId = 101 + i,
vcPlateSourceDesc = "asd" + i,
nvcPlateSourceArbDesc = "dsa" + i
});
}
stbPlateSource.IsEnglish = true;
EmirateComboBox.ItemsSource = Emirates;
List<stbPlateCateg> PlateCategory = new List<stbPlateCateg>();
for (int i = 0; i < 250; i++)
{
PlateCategory.Add(new stbPlateCateg()
{
Id = 201 + i,
tiPlateCategId = i + 1,
tiPlateSourceId = 101 + i,
vcPlateCategDesc = "asd" + i,
nvcPlateCategArbDesc = "dsa" + i
});
}
stbPlateCateg.IsEnglish = true;
CategoryComboBox.ItemsSource = PlateCategory.OrderBy(x => x.tiPlateCategId);
EmirateComboBox.SelectedIndex = 1;
CategoryComboBox.SelectedIndex = 0;
}
}
当我频繁更改组合框所选项目时,应用程序崩溃了,虽然我原来的应用程序经常崩溃,但这次崩溃时间很长。
当它在我调试的时候崩溃了,它只是崩溃了,没有任何异常。我不知道该怎么处理。
我没有任何证据但是我认为这是某种内存异常
这些组合框不能很好地工作,最后我不得不做一个隐藏的按钮。下面的列表框来处理这个
这样的<Button Name="EmirateComboButton" Click="EComboButton_Click" Style="{StaticResource ListboxButton}" />
<ListBox Name="EComboListBox" x:Uid="EComboListBox" Visibility="Collapsed" Tapped="EComboListBox_Tapped" SelectionChanged="EComboListBox_SelectionChanged"
Style="{StaticResource ListboxCombo}" DisplayMemberPath="vcPSource" ItemsSource="{Binding EBind}"
>
</ListBox>
你必须小心处理很多事情,比如检测点击隐藏列表框,动画等