C
C#3y 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.js7OP3y ago
How in C# I can edit this label ?
Lo
Lo3y 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.js7OP3y 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
Lo
Lo3y ago
np. If you use data-binding, You can solve perfect this problem. hang on. I will provide documentation.
Kaito.js7
Kaito.js7OP3y ago
Ok thx
Lo
Lo3y ago
then if you don't understand, let me check your code and help you.
Kaito.js7
Kaito.js7OP3y ago
No description
Kaito.js7
Kaito.js7OP3y ago
In this pic DesrLabel is the name of the label ?
Kaito.js7
Kaito.js7OP3y ago
Like that ?
No description
Lo
Lo3y ago
Yup. sure
Kaito.js7
Kaito.js7OP3y ago
So why I have an error ?
No description
Lo
Lo3y ago
can I check?
Kaito.js7
Kaito.js7OP3y ago
This is saying Text is not null
Lo
Lo3y ago
Can i check your project's code if the project have github repository?
Kaito.js7
Kaito.js7OP3y 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>
Lo
Lo3y ago
send me C# file. only this part.
Kaito.js7
Kaito.js7OP3y 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";
}
}
}
Lo
Lo3y ago
let me check.
Kaito.js7
Kaito.js7OP3y ago
So ?
Lo
Lo3y ago
You can change Name to x:Name in XAML.
Kaito.js7
Kaito.js7OP3y ago
No description
Kaito.js7
Kaito.js7OP3y ago
No description
Lo
Lo3y ago
Label's name.
Kaito.js7
Kaito.js7OP3y ago
Ho I forgot I change label in textblock to try something srry
Kaito.js7
Kaito.js7OP3y ago
No description
Lo
Lo3y ago
Yup.
Kaito.js7
Kaito.js7OP3y ago
Same
No description
Lo
Lo3y ago
You can try.
Kaito.js7
Kaito.js7OP3y ago
Tried I gave an error
Lo
Lo3y ago
Can I see the error?
Kaito.js7
Kaito.js7OP3y ago
Translation : A reference is required for the proprierty, method or field not static "MaintWindow.tested"
No description
Lo
Lo3y ago
sorry. i can't understand. I don't know about your language.
Kaito.js7
Kaito.js7OP3y ago
Ok np I translated ...
Kaito.js7
Kaito.js7OP3y ago
No description
Lo
Lo3y ago
You can try to write the code in constitutor.
Kaito.js7
Kaito.js7OP3y ago
Constitutor ?
Lo
Lo3y ago
in here.
No description
Kaito.js7
Kaito.js7OP3y ago
No description
Kaito.js7
Kaito.js7OP3y ago
Working So how can I do to make it possible on my function ?
Lo
Lo3y ago
you can make the function to public. and then you can try.
Kaito.js7
Kaito.js7OP3y ago
Ho thx
Lo
Lo3y ago
and you have to delete static.
Kaito.js7
Kaito.js7OP3y ago
Yeah I know Thx
Lo
Lo3y ago
welcome.\ If you have any qestion, you can contact me at the anytime. for it, you can send DM. okay?
Kaito.js7
Kaito.js7OP3y ago
Ok thxx
Lo
Lo3y 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.js7OP3y ago
Send me the Doc plz A bit
SinFluxx
SinFluxx3y 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.js7OP3y 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
Lo
Lo3y ago
?
Kaito.js7
Kaito.js7OP3y ago
I talk to @SinFluxx

Did you find this page helpful?