2015-11-20 2 views
0

У меня есть класс, как это:StackOverflow Возникло исключение при создании класса List

class FontSize 
{ 
    List<int> fontSizeList = new List<int>(new int[] { 10, 20, 25, 30, 35, 40, 45, 50, 60, 70, 80, 90 }); 
    public List<int> GetList() 
    { 
     return fontSizeList; 
    } 
} 

, когда я хочу назвать его в другом файле я называю класса с

AssetText.FontFamily fontFamily = new AssetText.FontFamily(); 

и я могу получите значение с помощью этого кода:

List<string> fontFamilyList = fontFamily.GetList(); 

Пока не существует никаких исключений. Но когда мне нужно что-то от другого (AssetList.xaml.cs)

public partial class EditText : Window 
    { 
     AssetText.FontFamily fontFamily = new AssetText.FontFamily(); 
     AssetText.FontSize fontSize = new AssetText.FontSize(); 
     AssetText.FontStyle fontStyle = new AssetText.FontStyle(); 
     AssetText.ScrollSpeed scrollSpeed = new AssetText.ScrollSpeed(); 
     AssetText.ScrollDirection scrollDirection = new AssetText.ScrollDirection(); 

     AssetList assetList = new AssetList(); 

     public EditText() 
     { 
      InitializeComponent(); 

      AssetListData selectedItem = assetList.getSelectedItem(); 

      List<string> fontFamilyList = fontFamily.GetList(); 
      List<int> fontSizeList = fontSize.GetList(); 
      List<string> fontStyleList = fontStyle.GetList(); 
      List<double> scrollSpeedList = scrollSpeed.GetList(); 
      List<string> scrollDirectionList = scrollDirection.GetList(); 

      //Values of ComboBoxes 
      fontFamily_ComboBox.ItemsSource = fontFamilyList; 
      fontSize_ComboBox.ItemsSource = fontSizeList; 
      fontStyle_ComboBox.ItemsSource = fontStyleList; 
      scrollSpeed_ComboBox.ItemsSource = scrollSpeedList; 
      scrollDirection_ComboBox.ItemsSource = scrollDirectionList; 

      fontFamily_ComboBox.SelectedValue = selectedItem.textFontFamily; 
      fontSize_ComboBox.SelectedValue = selectedItem.textFontSize; 
      fontStyle_ComboBox.SelectedValue = selectedItem.textFontStyle; 
      scrollSpeed_ComboBox.SelectedValue = selectedItem.textScrollSpeed; 
      scrollDirection_ComboBox.SelectedValue = selectedItem.textScrollDirection; 
     } 
    } 

Тогда Exception StackOverflow произойден в FontSize классе. Я не знаю, что произойдет с этим кодом, может кто-нибудь объяснить?

EDIT Я пытался использовать отладки и отладчик сохранить цикл в этом разделе:

AssetText.FontFamily fontFamily = new AssetText.FontFamily(); 
AssetText.FontSize fontSize = new AssetText.FontSize(); 
AssetText.FontStyle fontStyle = new AssetText.FontStyle(); 
AssetText.ScrollSpeed scrollSpeed = new AssetText.ScrollSpeed(); 
AssetText.ScrollDirection scrollDirection = new AssetText.ScrollDirection(); 

AssetList assetList = new AssetList(); 

EDIT 2 Я попытался сделать код как @ кабинка-жокей предложил, и исключение вызывается в режиме прерывания, открывается новое окно и говорит, что приложение находится в режиме разрыва. Это мой первый Exp получаю эту ошибку, я понятия не имею, на всех

EDIT 3 , как @peter говоря, что там может быть что-то, что создание нового EditText, может быть, это что-то отношение. У меня есть этот код в AssetList.xaml.cs

public void GridContextMenu_ItemClick(object sender, Telerik.Windows.RadRoutedEventArgs e) 
{ 
    MenuItem item = (e.OriginalSource as RadMenuItem).DataContext as MenuItem; 
    typeValue = ((AssetListData)AssetList_GridView.SelectedItem).assetType; 
    switch (item.Text) 
    { 
     case "Edit Asset": 
      if (typeValue == "abc") 
      { 
       editText.Show(); 
       this.Close(); 
       break; 
      } 
      else if (typeValue == "aaa") 
      { 
       editGraphic.Show(); 
       this.Close(); 
       break; 
      } 
      else if (typeValue == "bbb") 
      { 
       editVideo.Show(); 
       this.Close(); 
       break; 
      } 
      else if (typeValue == "xxx") 
      { 
       editLiveVideo.Show(); 
       this.Close(); 
       break; 
      } 
      break; 
     case "Delete Asset": 
      this.AssetList_GridView.Items.Remove(this.AssetList_GridView.SelectedItem); 
      break; 
    } 
} 
+0

Вам нужно будет опубликовать фактический код, ничто из этого не имеет смысла, и, похоже, оно не связано друг с другом. У вас есть класс FontSize, который вы не используете в каких-либо последующих фрагментах кода, но вы хотите, чтобы мы помогли вам выяснить, почему возникает StackOverflowException при его использовании. –

+0

@WillemvanRumpt wait, я скопирую его – Mirza

+0

Все еще не имеет смысла. Где вы получаете исключение в этом коде? –

ответ

0

Решенные

У меня есть:

EditText editText = new EditText(); 

внутри моего разделяемого класса в AssetList.xaml.cs, который вызывает цикл, когда я называю AssetList в EditText.xaml.cs Итак, я переместил его в метод, в котором он нужен.

Спасибо за помощь всем!

Смежные вопросы