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 8012457
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T19:20:16+00:00 2026-06-04T19:20:16+00:00

within a textblock i would like a text, depending on the value of a

  • 0

within a textblock i would like a text, depending on the value of a boolean property.
the text has to be taken using a DynamicResource, because of the multiple langauges the application supports.

there are two entries available in the DynamicResources, one for when the property is true, one for when the property is false.

i would like to solve this in xaml, so that the correct DynamicResource is shown, depending on the value of the property.

anybody an idea or this is possible ? (and how 😉 ?
thanks.

  • 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-04T19:20:17+00:00Added an answer on June 4, 2026 at 7:20 pm

    Below is solution for your problem.

    • ResourceDictionary
    <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                        xmlns:system="clr-namespace:System;assembly=mscorlib"
                        >
        <system:String x:Key="Lang1">Lang1 Message</system:String>
        <system:String x:Key="Lang2">Lang2 Message</system:String>
    </ResourceDictionary>
    
    • App.xaml
    <Application x:Class="MultiLang.App"
                 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                 StartupUri="MainWindow.xaml">
        <Application.Resources>
            <ResourceDictionary>
                <ResourceDictionary.MergedDictionaries>
                    <ResourceDictionary Source="LangResources.xaml" />
                </ResourceDictionary.MergedDictionaries>
            </ResourceDictionary>
        </Application.Resources>
    </Application>
    
    • MainWindow.xaml

      <Window.Resources>
          <vm:MainWindowViewModel x:Key="mainVM" />
      </Window.Resources>
      
      <Grid DataContext="{StaticResource mainVM}">
      
          <ToggleButton Name="btnLang" IsChecked="{Binding Var}" Content="Change lang" MaxWidth="100" MaxHeight="30">
      
          </ToggleButton>
      
          <TextBlock Margin="5" MaxHeight="30" VerticalAlignment="Top">
              <TextBlock.Style>
                  <Style TargetType="{x:Type TextBlock}">
                      <Style.Triggers>
                          <DataTrigger Binding="{Binding Path=DataContext.Var, RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=Grid}}" Value="True">
                              <Setter Property="Text" Value="{DynamicResource Lang1}" />
                          </DataTrigger>
                          <DataTrigger Binding="{Binding Path=DataContext.Var, RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=Grid}}" Value="False">
                              <Setter Property="Text" Value="{DynamicResource Lang2}" />
                          </DataTrigger>
                      </Style.Triggers>
                  </Style>
              </TextBlock.Style>
          </TextBlock> 
      </Grid>
      

    • MainWindowViewModel

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.ComponentModel;
    
    namespace MultiLang
    {
        public class MainWindowViewModel: INotifyPropertyChanged
        {
            private bool _var = false;
            public bool Var
            {
                get { return _var; }
                set
                {
                    _var = value;
                    OnPropertyChanged("Var");
                }
            }
    
            public event PropertyChangedEventHandler PropertyChanged;
            public void OnPropertyChanged(string name)
            {        
                PropertyChangedEventHandler handler = PropertyChanged;
                if (handler != null)
                {
    
                    handler(this, new PropertyChangedEventArgs(name));
                }
            }
        }
    }
    

    Better option is create two language files with same keys but with different values and merged proper files on runtime. In this case you don’t have to check boolean property every time!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am setting different text to a textblock depending on what control has been
I would like draw a vector-based graphic within a WPF ListBoxItem. The 2D shapes
In my app I'm displaying some user-provided text within a TextBlock. We found that
I'm creating a KPI like control and would like to apply multiple styles based
In my WP7 app, I'm using this guys method to find a TextBlock within
Is there a way to hide an inlined text within TextBlock? <TextBlock.Inlines> <Run Text=A
I need to be able to affect multiple Textblock elements within my TimerCallback. At
I have a Textblock within a scrollviewer around it. My application is completely controlled
Within my ASP.NET App I am using a Method to check user permissions to
I have a line of text in a textblock that reads: Detected [gesture] with

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.