Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8317077
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T21:30:21+00:00 2026-06-08T21:30:21+00:00

Background: I have an instance of a LabelService class in my Views that I

  • 0

Background:

I have an instance of a LabelService class in my Views that I use to get text from different languages.

This requires that I have code in the background as follows to populate the text in a TextBlock:

XAML:

<TextBlock Name="txtExample" Grid.Row="0" Margin="5,5,5,5"/>

C#:

// 'this' refers to the current class, the namespace of which is used to navigate
// through an XML labels file to find the correct label
string label = _labelService.GetSpecificLabel(this, txtExample.Name).Label
txtExample.Text = label;

Question:

Is it possible for me to have this functionality:

_labelService.GetSpecificLabel(this, txtExample.Name).Label

available in the XAML?

Supplementary Info:

just to explain what I mean by using the namespace to navigate the labels XML:

suppose class is defined as follows, in namespace

namespace My.App.Frontend
{
    public class MainWindow
    {
        string label = _labelService.GetSpecificLabel(this, txtExample.Name).Label
    }
}

The corresponding XML would be

<My>
  <App>
    <Frontend>
      <MainWindow>
          <txtExample label="I am the example text" />
      </MainWindow>
    </Frontend>
  </App>
</My>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T21:30:22+00:00Added an answer on June 8, 2026 at 9:30 pm

    In WPF the the MVVM Pattern is often used to achieve this.

    It is even considered bad practise to do such in the code behind,
    as it is not testable and not very maintainable.
    Leave the codebehind as empty as you can.

    That way, you have a ViewModel class which can be connected to your
    label service. Your view binds to the ViewModel then.

    Here is a very good Video tutorial on how to architect a WPF application:
    Jason Dollinger on MVVM

    The source code he develops in his tutorial is also available here:
    Source code of Jason Dollinger

    Here is a very simple ViewModel for you, just to let you have a starting point:
    (note that _labelService and txtExample are not set there at the moment)

    public class TextBoxViewModel : INotifyPropertyChanged
    {
        public TextBoxViewModel()
        {
            string label = _labelService.GetSpecificLabel(this, txtExample.Name).Label;
            this.text = label;
        }
    
        private string text;
    
        public string Text 
        { 
            get
            {
                return text;
            }
    
            set 
            {
                text = value;
                NotifyPropertyChanged("Text");
            }
        }
    
        public event PropertyChangedEventHandler PropertyChanged;
    
        private void NotifyPropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }
    }
    

    In XAML, the Binding part is important:

    <TextBox Text="{Binding Text}" Height="26" HorizontalAlignment="Left" Margin="77,215,0,0" Name="textBox1" VerticalAlignment="Top" Width="306" />
    

    In Codebehind (or better: where you do your scaffolding)

    public MainWindow()
    {
        InitializeComponent();
    
        this.DataContext = new TextBoxViewModel();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Background: I have a WebPart that makes use of the SPCalendarView control and in
If I have an instance of a class that I store in a session
Suppose you have a class where you start some background thread: this class could
Background: I have an application that I have nicely separated my interface logic from
In my web application, I have a background service. This service uses Generator class
Background I have a function that takes a config object as an argument. Within
Background : I have a few different threads which each need to write to
Background I have a dimension table that has a single record for each day.
Background: I have this with rollup query defined in MySQL: SELECT case TRIM(company) when
Background: I have enclosed (parent) class E with nested class N with several instances

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.