2017-07-20 8 views
1

Visual Studio 2010(対象フレームワーク:.NET Framework 4 Client Profile)を使用して2年前にWinforms C#アプリケーションを開発しました。でTabControlを異なる.NETフレームワークで使用する場合

このアプリケーションには、Form1:Form、複数のタブページを持つtabcontrolを持つINotifyPropertyChangedがあります。フォームの構築時に表示されないタブページ上にあるコントロールにフォームのカスタムプロパティをバインドしました。バインディングは次のようになります。

BindingSource BndFrom1 = new BindingSource(); 
BndFrom1.DataSource = typeof(Form1); 
BndFrom1.Add(this); 

TxtTemperature.DataBindings.Add("Text", BndFrom1, "TemperatureString", true, DataSourceUpdateMode.OnPropertyChanged); 

これは問題なく動作します。 .NET Framework 4.6でWindows 10に切り替えた後、アプリケーションは突然プロッパーで動作せず、別のタブページに切り替えると完全に遅くなったり詰まったりしました。私がタブページの順序を変更した場合、それは常にうまく機能する最初のタブページでした。 は、私はすべてのtabpages上

private static void CreateControls(Control control) 
     { 
      CreateControl(control); 
      foreach (Control subcontrol in control.Controls) 
      { 
       CreateControl(subcontrol); 
      } 
     } 
     private static void CreateControl(Control control) 
     { 
      var method = control.GetType().GetMethod("CreateControl", BindingFlags.Instance | BindingFlags.NonPublic); 
      var parameters = method.GetParameters(); 

      method.Invoke(control, new object[] { true }); 
     } 

を呼び出すことによってinvissibleコントロールを作成するために、Form1を「強制」してみましたが、これは動作しませんでした。
タブページのコントロールですべてのデータバインディングを削除した後、問題は解決されました。

私は、データバインディングを使用して、Windows 7 PC上でまだプロッパーを実行している私のアプリケーションの最初のバージョンを持っていました。しかし、.NET Framework 4.7へのアップデート後、それは同じ問題を抱えていたし、新しいバージョンのアプリケーションをインストールした後は消えてしまった。

これは既知の問題ですか?その場合、説明と解決方法はありますか?誰かが私がバインディングを使用し続けることができるよりよい解決策を持っていますか?事前に

おかげで、

エレックは

答えて

0

私たちは、しかし、誰成功し、このバグを再現しようとしました。問題を示すサンプルアプリケーションを共有していただけますか? 1. winformsアプリケーションを作成します 2. 2つのタブを持つラベルとタブコントロールをフォームに追加します 3.タブコントロールの2番目のタブにテキストボックスを追加します 4.データバインドラベルをオンにします2番目のタブのテキストボックスの内容を反映するフォームのプロパティへのフォーム コードと比較してこの再現の試行で何が欠落していますか?また、SQLデータベースへのデータバインディングも実験しました。そして4.0と4.7のバージョンのフレームワークには何の違いも見られませんでした。ここで

はForm1.csのコードです:

using System; 
using System.ComponentModel; 
using System.Runtime.CompilerServices; 
using System.Windows.Forms; 

namespace WindowsFormsApp5 
{ 
    public partial class Form1 : Form, INotifyPropertyChanged 
    { 
     public Form1() 
     { 
      InitializeComponent(); 

      BindingSource bindingSource = new BindingSource(); 
      bindingSource.DataSource = typeof(Form1); 
      bindingSource.Add(this); 

      label1.DataBindings.Add("Text", bindingSource, "CustomProperty1", true, 
       DataSourceUpdateMode.OnPropertyChanged); 
     } 

     public event PropertyChangedEventHandler PropertyChanged; 

     private void NotifyPropertyChanged([CallerMemberName] String propertyName = "") 
     { 
      PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); 
     } 

     public string CustomProperty1 { 
      get { return textBox1.Text; } 
      set { 
       NotifyPropertyChanged(); 
      } 
     } 

     private void Form1_Load(object sender, EventArgs e) 
     { 
      textBox1.Text = "thing1"; 
     } 

     private void textBox1_TextChanged(object sender, EventArgs e) 
     { 
      NotifyPropertyChanged("CustomProperty1"); 
     } 
    } 
} 

はありがとう、ターニャ

関連する問題