Click here to Skip to main content
15,891,828 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

need help with plugin development (C#, visual studio, plugin for Smart Client). In example below I can change "CONTENT" for bbt:
C#
private void bbt_Click(object sender, RoutedEventArgs e)
    {
      var bbt = sender as Button;
      bbt.Content = "TEST";
    }


bbt.Content = "TEST";

but how can I change content for other buttons, defined in my code? For example, another button name is "action1"?

action1.Content = "TEST";

It looks like I need to add some prefix before referring to "action1", because otherwise it's not visible and generates:

CS0103 The name 'action1' does not exist in the current context

What I have tried:

private void bbt_Click(object sender, RoutedEventArgs e)

    {

      var bbt = sender as Button;

 

      this.action1.Content = "TEST";

 

    }
Posted
Updated 9-Sep-19 22:36pm
v2
Comments
Richard MacCutchan 10-Sep-19 3:35am    
You cannot access an object that is not part of your class.
PureNsanity 10-Sep-19 12:41pm    
To tack onto what Richard said... You can have XAML with named content that isn't part of the UserControl. For example, if you have named content within a template. If you're getting that compiler error it's very likely that's the case, but to tell you specifically why you'd have to include your XAML.
Member 14584621 10-Sep-19 12:44pm    
Ok, but how can I solve this issue? Here is the whole code, so you guys can see how the template I'm using looks like, where are button definitions etc:

https://shrib.com/#IcinRLal40GYR48ZEpCf

1 solution

You are doing it wrong.

The basic concept for WPF application is to use Routed Events[^], but the real power of WPF is to use XAML[^] and MVVM pattern[^].

In a short: you have to start thinking about application functionalities, especially what control should be bind to what model property. And what event fires up the UI update.

Please, read these articles:
Data Binding Overview | Microsoft Docs[^]
Understanding the basics of MVVM design pattern – Microsoft Gulf Technical Community[^]
MVVM Pattern in WPF: A Simple Tutorial for Absolute Beginners[^]
How to: Implement Property Change Notification | Microsoft Docs[^]
Explain INotifyPropertyChanged In WPF - MVVM[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900