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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T13:41:27+00:00 2026-05-15T13:41:27+00:00

I have a ListBox whose ItemsSource is bound to a list of objects. The

  • 0

I have a ListBox whose ItemsSource is bound to a list of objects. The Listbox has a ItemTemplate with a DataTemplate containing a TextBlock. The textblock’s Text is bound to the object’s Name property (i.e. Text=”{Binding Name}”).

I would like to provide a radio button to show different views of the same list. For example allow a user to toggle between the Name property and an ID property.

I found a SO answer for this at 2381740 but I also have border and a textbox style set in data template (see code below).

Is there anyway to just reset the Textblock binding? I don’t want to have to recreate the entire datatemplate. Actually I’m not even sure how to do that, is there an easy way to translating xaml to code?.

Thanks
Cody

<DataTemplate>
  <Border Margin="0 0 2 2"
          BorderBrush="Black"
          BorderThickness="3"
          CornerRadius="4"
          Padding="3">
      <TextBlock Style="{StaticResource listBoxItemStyle}"
                 Text="{Binding Name}" />
  </Border>
</DataTemplate>
  • 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-05-15T13:41:27+00:00Added an answer on May 15, 2026 at 1:41 pm

    Just make it simple for yourself and use two textblocks and hide one of them.

    XAML:

    <Window x:Class="Test.Window1"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      Height="300" Width="300">
    
      <Window.Resources>
        <BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" />
      </Window.Resources>
    
      <StackPanel>
        <RadioButton Name="nameRadioBtn" Content="Name" IsChecked="True"/>
        <RadioButton Name="lengthRadioBtn" Content="Length" />
        <ListBox
          ItemsSource="{Binding Path=Items}">
          <ListBox.ItemTemplate>
            <DataTemplate>
              <Border BorderBrush="Red" BorderThickness="1">
                <Grid>
                  <TextBlock 
                    Text="{Binding .}" 
                    Visibility="{Binding Path=IsChecked, ElementName=nameRadioBtn, 
                      Converter={StaticResource BooleanToVisibilityConverter}}" />
                  <TextBlock 
                    Text="{Binding Path=Length}" 
                    Visibility="{Binding Path=IsChecked, ElementName=lengthRadioBtn,
                      Converter={StaticResource BooleanToVisibilityConverter}}" />
                </Grid>
              </Border>
            </DataTemplate>
          </ListBox.ItemTemplate>
        </ListBox>
      </StackPanel>        
    </Window>
    

    Code behind:

    using System.Collections.Generic;
    using System.Windows;
    
    namespace Test
    {
        public partial class Window1 : Window
        {
            public Window1()
            {
                InitializeComponent();
    
                DataContext = this;
            }
    
            public IEnumerable<string> Items
            {
                get
                {
                    return new List<string>() {"Bob", "Sally", "Anna"};
                }
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

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.