2012-12-24 8 views
0

저는 C# 및 특히 WPF와 관련하여 도움을 청합니다. : D다른 클래스의 WPF - progressbar 업데이트

WPF 프로젝트가 있으며 다른 클래스의 진행률 값을 업데이트해야합니다. progressbar는 'NdWindow'클래스에 있으며 클래스 'Automator'에서 그 값을 업데이트해야합니다.

나는 이미 몇 가지 시도했지만 아무것도 나를 위해 일했습니다. 'NdWindow'클래스에서

는 :
public partial class NdWindow : Window 
{ 
    public NdWindow() 
    { 
     InitializeComponent(); 
    } 

    public NdWindow(int progress) 
    { 
     InitializeComponent(); 
     setprogress(progress); 
    } 

    public void setprogress(int progress) 
    { 
     this.progressBar.Value = progress; 
     MessageBox.Show(Convert.ToString(progress)); 
    } 

그리고 '자동화'클래스

: 나는 프로그램, 메시지 박스 팝업을 실행하고 나에게 값을 표시하는 경우

public static void post() 
{ 
    NdWindow test = new NdWindow(); 
    test.setprogress(10); 
} 

나는가 setProgress 내 보낸(). 또한 생성자 내에서 값을 보냈지 만 도움이되지 않았습니다.

가능한 경우 도와주세요. : D

고마워요!

PS : '게시'기능은 버튼 클릭으로 실행됩니다. 나는 그 코드를 여기서 작성하지 않았다. 나는 이것이 당신에게 문제가되지 않기를 바랍니다. :-)

+0

확인이 솔루션 http://stackoverflow.com/questions/5789926/update-a-progressbar-from-another-thread?rq에 NdWindow를 보낼 수 = 1 – Nogard

답변

3

post 메서드에서 새로 만든 NdWindow을 만들면 마녀가 진행률 막대 값을 변경하려는 창이 아닙니다.

어떻게 든 NdWindowAutomator 클래스로 가져와야합니다.

public class Automator 
{ 
    private NdWindow ndWindow; 
    public Automator(NdWindow ndwindow) 
    { 
     this.ndWindow = ndwindow; 
    } 

    public void Post() 
    { 
     ndWindow.setprogress(10); 
    } 
} 

public partial class NdWindow : Window 
{ 
    private Automator automator; 
    public NdWindow() 
    { 
     InitializeComponent(); 
     this.automator = new Automator(this); 
    } 

    private void button1_Click(object sender, RoutedEventArgs e) 
    { 
     Automator.Post(); 
    } 
} 

또는 당신은 당신의 post 방법

public class Automator 
{ 
    public static void Post(NdWindow ndWindow) 
    { 
     ndWindow.setprogress(10); 
    } 
} 

public partial class NdWindow : Window 
{ 
    private void button1_Click(object sender, RoutedEventArgs e) 
    { 
     Automator.Post(this); 
    } 
} 
+0

대단히 감사합니다! 귀하의 솔루션은 완벽하게 작동합니다. :-디 – RazvanR104

관련 문제