C
C#2w ago
Erich21

Changing the visibility/animations of UI elements

hello, i have an image in the xaml, like this
<Image Name="testImage" Canvas.Top="-16" Canvas.Left="246" HorizontalAlignment="Left" VerticalAlignment="Top" Height="64" Width="64" Source="/button_onbeat.png"></Image>
<Image Name="testImage" Canvas.Top="-16" Canvas.Left="246" HorizontalAlignment="Left" VerticalAlignment="Top" Height="64" Width="64" Source="/button_onbeat.png"></Image>
now i want to control its visibility w the help of an external class in another file i saw that i can inherit the : MainWindow in a class and i can access the elements however i tried changing the visibility and opacity at a certain point and it didnt work, in 2 ways
testImage.Visibility= Visibility.Collapsed;
// and
Application.Current.Dispatcher.Invoke(() =>
{
testImage.Visibility = Visibility.Collapsed;
});
testImage.Visibility= Visibility.Collapsed;
// and
Application.Current.Dispatcher.Invoke(() =>
{
testImage.Visibility = Visibility.Collapsed;
});
No description
4 Replies
Hannsen
Hannsen2w ago
Inheriting MainWindow, wont give you the same instance which is rendered.
Hannsen
Hannsen2w ago
Data binding overview - WPF .NET
Learn about data binding in Windows Presentation Foundation for .NET. You can bind data to UI elements to create dynamic apps.
Hannsen
Hannsen2w ago
If you post some code, than we can assist why it is not working as you expect
Erich21
Erich21OP2w ago
c#
if ((DateTime.Now - leftHandCollisionStartTime.Value).TotalSeconds >= 3)
{
// Collision sustained for 5 seconds, show success message
leftHandCollisionStartTime = null; // Reset tracking
MessageBox.Show("Left Hand Success!");
window.testImage.Visibility = Visibility.Collapsed;
window.testImage.Opacity = 0.0;
window.mylefthandPosition_coords.Opacity = 0.0;
Application.Current.Dispatcher.Invoke(() =>
{
window.testImage.Visibility = Visibility.Hidden;
});
}
c#
if ((DateTime.Now - leftHandCollisionStartTime.Value).TotalSeconds >= 3)
{
// Collision sustained for 5 seconds, show success message
leftHandCollisionStartTime = null; // Reset tracking
MessageBox.Show("Left Hand Success!");
window.testImage.Visibility = Visibility.Collapsed;
window.testImage.Opacity = 0.0;
window.mylefthandPosition_coords.Opacity = 0.0;
Application.Current.Dispatcher.Invoke(() =>
{
window.testImage.Visibility = Visibility.Hidden;
});
}
Inside a function that i call, theres this condition (which does happen because the message box does appear), however the image does not become invisible in my external class, i have a
MainWindow window;
MainWindow window;
member of the class and in the mainwindow class, i send 'this' to the public constructor of my external class
public MainWindow()
{
InitializeComponent();

KinectFunctions = new KinectFunctions(this);
...
}

public class KinectFunctions
{
MainWindow window;
...
public KinectFunctions(MainWindow window) {
this.window = window;
}
}
public MainWindow()
{
InitializeComponent();

KinectFunctions = new KinectFunctions(this);
...
}

public class KinectFunctions
{
MainWindow window;
...
public KinectFunctions(MainWindow window) {
this.window = window;
}
}
Want results from more Discord servers?
Add your server