Я работаю над проектом и должен получить доступ к метке из обычного класса .cs.
НЕ от MainWindow.xaml.cs!Контроль доступа из обычного класса (.cs)
MainWindow.xaml
: содержит ярлык lblTag
.
Class.cs нужно выполнить:
lblTag.Content = "Content";
Как я могу реализовать это?
Я только что закончил с 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:
[...]
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;
}
[...]
Дайте контроль имя, например '<Ярлык x: Name =" myLabel "... />' – Phil
не будет lblTag.Content = "String"; быть достаточным? – Bahamut
Если элемент управления * назван * lblTag, тогда вы должны просто использовать «lblTag.Content» (без кавычек). Попробуйте ввести «это». и посмотрите, что Intellisense сообщает вам о элементах управления на XAML – kaj