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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T01:42:33+00:00 2026-06-09T01:42:33+00:00

I have defined two datatemplates for my listBox for which I am using a

  • 0

I have defined two datatemplates for my listBox for which I am using a DataTemplateSelector to decide which one to be rendered for an item. However, One of my templates has an embedded button which when clicked should display a form in place. So I have setup a boolean property and implemented INotifyPropertyChanged; so that when the boolean property is true, the current template is replaced by a third template.

This is the code for the button.

        Activity activityItem = (Activity)listBox1.Items[listBox1.SelectedIndex]; 
        activityItem.ShowFeedbackForm = 1;

This is my XAML:

    <Grid.Resources>
    <DataTemplate x:Key="completedActivityTemplate">
        <Grid Name="templateGrid" >
    ... 
    <DataTemplate x:Key="activityTemplate">
        <Grid Name="templateGrid" >
    ...
    <DataTemplate x:Key="feedbackFormTemplate">
        <Grid Name="templateGrid" >
    ...    
     <Style TargetType="ListBoxItem" x:Key="ContainerStyle">
        <Setter Property="Height" Value="55" />
        <Setter Property="Background" Value="Transparent" />
        <Style.Triggers>
            <Trigger Property="IsKeyboardFocusWithin" Value="True">
                <Setter Property="IsSelected" Value="True" />
            </Trigger>
            <DataTrigger Binding="{Binding showFeedbackForm}" Value="1">
                <Setter Property="ContentTemplate" Value="{StaticResource feedbackFormTemplate}" />
            </DataTrigger>
        </Style.Triggers>
    </Style>
    </Grid.Resources>
    <ListBox Grid.Row="1" Name="listBox1" IsSynchronizedWithCurrentItem="True" 
         ScrollViewer.HorizontalScrollBarVisibility="Disabled"
         VerticalContentAlignment="Stretch" Background="Transparent"
         BorderThickness="0" ItemContainerStyle="{StaticResource ContainerStyle}"
         HorizontalContentAlignment="Stretch" Margin="-3,0,0,0"
         ItemTemplateSelector="{StaticResource myDataTemplateSelector}">
    </ListBox>

So when the user clicks the button, the value of 1 is set for the ShowFeedbackForm for that item which is when the template showing a feedback form is to be displayed but nothing is happening. My ObservableCollection(one way) bindings are working fine.

  • 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-09T01:42:35+00:00Added an answer on June 9, 2026 at 1:42 am

    In the button click handler, I set the boolean value the bound item and then rebind the datatemplate selector for the listBox.

            ListBoxItem currentItem = (ListBoxItem)(listBox1.ItemContainerGenerator.ContainerFromItem(listBox1.Items.CurrentItem));
            Activity activityItem = (Activity)listBox1.Items[listBox1.SelectedIndex]; 
            activityItem.ShowFeedbackForm = 1;
            listBox1.ItemTemplateSelector = new ActivityFeedDataTemplateSelector();
    

    My ActivityFeedDataTemplateSelector returns the desired template name if the boolean is set.

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

Sidebar

Related Questions

Preface: I have two entities defined as a one-to-many relationship: A <<-------> B. B's
I have defined two properties, "Name" and "ID", for an object which I use
I am using Jags and I have defined two different models to estimate a
I have an app which is a UITabBarController, I have defined two subviews Both
I have defined two classes in javascript as follows. function ParentClass(){ this.one = function(){
I have two datatemplates defined as static resources. Now I have a combobox with
I have defined two dimensional array using following definition typedef std::vector<std::vector<short> > table_t; Can
I have defined two models where each one references the other, like so: class
I have defined two endpoints in my App.Config file as <system.serviceModel> <services> <service name=HostDirectAddress.ITestService
I have defined the following two functions test <- function(t) { return( (0.5*eta^2/theta)*(1-exp(-2*theta*t)) )

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.