나는 프로젝트에서 작업 중이므로 일반 class.cs에서 레이블에 액세스해야합니다.
MainWindow.xaml.cs에서 가져온 것이 아닙니다!일반 클래스 (.cs)에서 액세스 제어
MainWindow.xaml
: 레이블 lblTag
을 포함합니다.
lblTag.Content = "Content";
내가 그것을 어떻게 실현할 수 :
Class.cs 실행할 필요가 있겠습니까?
결국 나는 InvalidOperationExceptions
으로 끝납니다.
Window1.xaml.cs :
public Window1()
{
InitializeComponent();
[...]
}
[...]
StreamElement se1;
StreamElement se2;
private void Window_Loaded(object sender, RoutedEventArgs e)
{
[...]
se1 = new StreamElement(this);
se2 = new StreamElement(this);
[...]
}
[...]
StreamElement.cs : 당신은 당신의 클래스에서 MainWindow를 클래스의 인스턴스에 대한 참조를 필요
[...]
private Window1 _window;
[...]
public StreamElement(Window1 window)
{
_window = window;
}
[...]
//metaSync is called, whenever the station (it's a sort of internet radio recorder)
//changes the meta data
public void metaSync(int handle, int channle, int data, IntPtr user)
{
[...]
//Tags just gets the meta data from the file stream
Tags t = new Tags(_url, _stream);
t.getTags();
//throws InvalidOperationException - Already used in another thread
//_window.lblTag.Content = "Content" + t.title;
}
[...]
Class.cs
에에
' ' – Phil
은 lblTag.Content = "String"이 아닙니다; 충분하다? – Bahamut
컨트롤이 * named * lblTag 인 경우 "lblTag.Content"(따옴표 제외)를 사용할 수 있어야합니다. "this"라고 입력 해보십시오. Intellisense에서 XAML의 컨트롤에 대해 알려주는 내용을 확인하십시오. – kaj