2017-02-15 10 views
0

MainWindow.xaml.csから呼び出されるWPFのウィンドウには、複数の要素で定義されたクラスIがあります。このクラスタイプのarrayを作成します。クラス配列をあるWPFウィンドウから別のウィンドウに戻すにはどうすればよいですか?

FieldLengths.xaml.cs では私が持っている:

:MainWindow.xaml.cs

try 
     { 
      dtFields = ((DataView)dtGrid.ItemsSource).ToTable(); 
      intNumFields = 0; 

      for (int intRowCnt = 0; intRowCnt < dtFields.Rows.Count; intRowCnt++) 
      { 
       bool blnJustifyRight = Convert.ToBoolean(dtFields.Rows[intRowCnt][2]); 
       bool blnJustifyLeft = Convert.ToBoolean(dtFields.Rows[intRowCnt][3]); 
       bool blnLeftZeroFill = Convert.ToBoolean(dtFields.Rows[intRowCnt][4]); 
       bool blnRightZeroFill = Convert.ToBoolean(dtFields.Rows[intRowCnt][5]); 

       if (blnJustifyRight || blnJustifyLeft || blnLeftZeroFill || blnRightZeroFill) 
       { 

        Array.Resize(ref fjfFields, intNumFields + 1); 
        fjfFields[intNumFields] = new FieldJustifyFill 
        { 
         ColumnNumber = intRowCnt, 
         RightJustify = blnJustifyRight, 
         LeftJustify = blnJustifyLeft, 
         LeftZeroFill = blnLeftZeroFill, 
         RightZeroFill = blnRightZeroFill 
        }; 

        intNumFields += 1; 
       } 
      } 
     } 
     catch (Exception ex) 
     { 
      string strMsg; 

      strMsg = "RefreshRowSize, error '" + ex.Message + "' has occurred."; 
      System.Windows.MessageBox.Show(strMsg); 
     } 

は、私はこれを持っている:

public partial class FieldLengths : Window 
{ 
    public FieldJustifyFill[] fjfFields = new FieldJustifyFill[0]; 
    public class FieldJustifyFill 
    { 
     public int ColumnNumber { get; set; } 
     public bool RightJustify { get; set; } 
     public bool LeftJustify { get; set; } 
     public bool LeftZeroFill { get; set; } 
     public bool RightZeroFill { get; set; } 
    } 

I負荷がこの方法です

public partial class MainWindow : Window 
{ 
    FieldJustifyFillDest[] fjfFieldsDest = new FieldJustifyFillDest[0]; 

日常的に私はVAを取得しようとするこのようなFixedLengths.xaml.csから梅毒:

FieldLengths flWin = new FieldLengths(strInputName, strFieldInfo, null, null, null, strMappingMetadata); 
       flWin.Left = System.Windows.Application.Current.MainWindow.Left + 15; 
       flWin.Top = desktopWorkArea.Top + 25; 
       flWin.ShowDialog(); 

       if (flWin.blnFLCreateFile) 
       { 
        string strPrgFileName; 

        Array.Resize(ref fjfFieldsDest, flWin.fjfFields.Length); 

        for (int i = 0; i < flWin.fjfFields.Length; i++) 
        { 
         int intColumnNumber = flWin.fjfFields[i].ColumnNumber; 
         bool blnRightJustify = flWin.fjfFields[i].RightJustify; 
         bool blnLeftJustify = flWin.fjfFields[i].LeftJustify; 
         bool blnLeftZeroFill = flWin.fjfFields[i].LeftZeroFill; 
         bool blnRightZeroFill = flWin.fjfFields[i].RightZeroFill; 

         fjfFieldsDest[i] = new FieldJustifyFillDest 
         { 
          ColumnNumber = intColumnNumber, 
          RightJustify = blnRightJustify, 
          LeftJustify = blnLeftJustify, 
          LeftZeroFill = blnLeftZeroFill, 
          RightZeroFill = blnRightZeroFill 
         }; 
        } 

は、変数intColumnNumberblnRightJustifyblnLeftJustifyblnLeftZeroFillblnRightZeroFillは正しい値を持っていますが、それはfjfFieldsDestにロードされたときに[i]は、彼らが正しくありません。

クラス配列を正しく返すにはどうすればよいですか?私はどこにでもよい例を見つけることができません。

+0

デバッガを使用して、値が正しくない理由を確認します。コードの実行前にブレークポイントを置く。 F11を押して、何が起こっているのかを確認してください。 –

+0

配列を使いこなす代わりに、一般的な 'List 'をチェックする必要があります。 –

+0

#Jeroen van Langen - これを行う方法を説明できますか? – Cass

答えて

0

私の謝罪、私のコードは正しくコードされて動作しています。デバッガは、クラス要素をアルファベット順に並べ替え、気付かなかった。申し訳ありません。しかし、私がコーディングしている方法が正しいとは限りません。コードを正しく書くためにフィードバックを歓迎します。

関連する問題