C
C#2y ago
Kaito.js7

How do I modify a label on my XAML code With a C# Function ?

Hi, I have a label with some data and I want to edit it when I launch my function
No description
52 Replies
Kaito.js7
Kaito.js7OP2y ago
How in C# I can edit this label ?
Andrii Kerrn
Andrii Kerrn2y ago
You can use data binding. are you using WPF? If you are using WPF, this is no problem. How do you think about it?
Kaito.js7
Kaito.js7OP2y ago
Yes Yeah but idk how to do Like I have to the the name of my label.Text = "What I want"; Idk how to edit my text
Andrii Kerrn
Andrii Kerrn2y ago
np. If you use data-binding, You can solve perfect this problem. hang on. I will provide documentation.
Kaito.js7
Kaito.js7OP2y ago
Ok thx
Andrii Kerrn
Andrii Kerrn2y ago
then if you don't understand, let me check your code and help you.
Kaito.js7
Kaito.js7OP2y ago
No description
Kaito.js7
Kaito.js7OP2y ago
In this pic DesrLabel is the name of the label ?
Kaito.js7
Kaito.js7OP2y ago
Like that ?
No description
Andrii Kerrn
Andrii Kerrn2y ago
Yup. sure
Kaito.js7
Kaito.js7OP2y ago
So why I have an error ?
No description
Andrii Kerrn
Andrii Kerrn2y ago
can I check?
Kaito.js7
Kaito.js7OP2y ago
This is saying Text is not null
Andrii Kerrn
Andrii Kerrn2y ago
Can i check your project's code if the project have github repository?
Kaito.js7
Kaito.js7OP2y ago
That's a private project I'll edit it to left only the important part So the XAML
<Window x:Class="ToxicMenuWPF.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:ToxicMenuWPF"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Grid>
<CheckBox>Aimbot</CheckBox>
<CheckBox Margin="0,25,0,0">XA</CheckBox>
<CheckBox Margin="0,50,0,0">WD</CheckBox>
<Label Name="tested" Margin="0,100,0,0"></Label>
</Grid>
</Window>
<Window x:Class="ToxicMenuWPF.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:ToxicMenuWPF"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Grid>
<CheckBox>Aimbot</CheckBox>
<CheckBox Margin="0,25,0,0">XA</CheckBox>
<CheckBox Margin="0,50,0,0">WD</CheckBox>
<Label Name="tested" Margin="0,100,0,0"></Label>
</Grid>
</Window>
Andrii Kerrn
Andrii Kerrn2y ago
send me C# file. only this part.
Kaito.js7
Kaito.js7OP2y ago
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Runtime.InteropServices;
using System.Security.Cryptography;
using System.Threading;
using System.Windows.Forms;
using Memory;
using System.Buffers;
using Swed32;
using Microsoft.VisualBasic.Devices;
using System.Security.Cryptography.Xml;
using System.Numerics;
using System.Threading.Tasks;
using ToxicMenuWPF.Helpers;
using ToxicMenuWPF.Models;
using ToxicMenuWPF.src;

namespace ToxicMenuWPF
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
///
public partial class MainWindow : Window
{
[DllImport("user32.dll")]

static extern short GetAsyncKeyState(Keys vK);

public MainWindow()
{
InitializeComponent();

Menu_Exec();
}

static void Menu_Exec()
{
tested.Content = "Test";
}
}
}
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Runtime.InteropServices;
using System.Security.Cryptography;
using System.Threading;
using System.Windows.Forms;
using Memory;
using System.Buffers;
using Swed32;
using Microsoft.VisualBasic.Devices;
using System.Security.Cryptography.Xml;
using System.Numerics;
using System.Threading.Tasks;
using ToxicMenuWPF.Helpers;
using ToxicMenuWPF.Models;
using ToxicMenuWPF.src;

namespace ToxicMenuWPF
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
///
public partial class MainWindow : Window
{
[DllImport("user32.dll")]

static extern short GetAsyncKeyState(Keys vK);

public MainWindow()
{
InitializeComponent();

Menu_Exec();
}

static void Menu_Exec()
{
tested.Content = "Test";
}
}
}
Andrii Kerrn
Andrii Kerrn2y ago
let me check.
Kaito.js7
Kaito.js7OP2y ago
So ?
Andrii Kerrn
Andrii Kerrn2y ago
You can change Name to x:Name in XAML.
Kaito.js7
Kaito.js7OP2y ago
No description
Kaito.js7
Kaito.js7OP2y ago
No description
Andrii Kerrn
Andrii Kerrn2y ago
Label's name.
Kaito.js7
Kaito.js7OP2y ago
Ho I forgot I change label in textblock to try something srry
Kaito.js7
Kaito.js7OP2y ago
No description
Andrii Kerrn
Andrii Kerrn2y ago
Yup.
Kaito.js7
Kaito.js7OP2y ago
Same
No description
Andrii Kerrn
Andrii Kerrn2y ago
You can try.
Kaito.js7
Kaito.js7OP2y ago
Tried I gave an error
Andrii Kerrn
Andrii Kerrn2y ago
Can I see the error?
Kaito.js7
Kaito.js7OP2y ago
Translation : A reference is required for the proprierty, method or field not static "MaintWindow.tested"
No description
Andrii Kerrn
Andrii Kerrn2y ago
sorry. i can't understand. I don't know about your language.
Kaito.js7
Kaito.js7OP2y ago
Ok np I translated ...
Kaito.js7
Kaito.js7OP2y ago
No description
Andrii Kerrn
Andrii Kerrn2y ago
You can try to write the code in constitutor.
Kaito.js7
Kaito.js7OP2y ago
Constitutor ?
Andrii Kerrn
Andrii Kerrn2y ago
in here.
No description
Kaito.js7
Kaito.js7OP2y ago
No description
Kaito.js7
Kaito.js7OP2y ago
Working So how can I do to make it possible on my function ?
Andrii Kerrn
Andrii Kerrn2y ago
you can make the function to public. and then you can try.
Kaito.js7
Kaito.js7OP2y ago
Ho thx
Andrii Kerrn
Andrii Kerrn2y ago
and you have to delete static.
Kaito.js7
Kaito.js7OP2y ago
Yeah I know Thx
Andrii Kerrn
Andrii Kerrn2y ago
welcome.\ If you have any qestion, you can contact me at the anytime. for it, you can send DM. okay?
Kaito.js7
Kaito.js7OP2y ago
Ok thxx
Andrii Kerrn
Andrii Kerrn2y ago
But I think, You have to use data binding in modern projects. that's good. All of project with WPF are using MVVM pattern. Did you know about it?
Kaito.js7
Kaito.js7OP2y ago
Send me the Doc plz A bit
SinFluxx
SinFluxx2y ago
You said send you the docs, that's a search for the docs, learning to search for documentation is an important skill
Kaito.js7
Kaito.js7OP2y ago
Wrong conv srry Yeah but before he said that he'll send me a doc so I was thinking about a more understandable doc not the microsoft doc I got it Here
Andrii Kerrn
Andrii Kerrn2y ago
?
Kaito.js7
Kaito.js7OP2y ago
I talk to @SinFluxx

Did you find this page helpful?