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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T06:28:47+00:00 2026-06-05T06:28:47+00:00

I have this code for xaml section <ListBox Margin=0,0,-12,0 Visibility=Visible ItemsSource={Binding QuestionsCurrent.Answers}> <ListBox.ItemTemplate> <DataTemplate>

  • 0

I have this code for xaml section

<ListBox Margin="0,0,-12,0" Visibility="Visible" ItemsSource="{Binding QuestionsCurrent.Answers}">
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <local:TemplateSelectorPollPage Content="{Binding QuestionsCurrent.Answers}">
                            <local:TemplateSelectorPollPage.RadioButtonField>
                                <DataTemplate>
                                    <StackPanel Orientation="Horizontal" Width="400" Margin="10">
                                        <RadioButton></RadioButton>
                                        <TextBlock Text="{Binding pavalue}" ></TextBlock>
                                    </StackPanel>
                                </DataTemplate>
                            </local:TemplateSelectorPollPage.RadioButtonField>
                            <local:TemplateSelectorPollPage.RadioButtonTextField>
                                <DataTemplate>
                                    <StackPanel Orientation="Horizontal" Width="400" Margin="10">
                                        <RadioButton></RadioButton>
                                        <TextBox Text="{Binding pavalue}" ></TextBox>
                                    </StackPanel>
                                </DataTemplate>
                            </local:TemplateSelectorPollPage.RadioButtonTextField>
                            <local:TemplateSelectorPollPage.CheckBoxField>
                                <DataTemplate>
                                    <StackPanel Orientation="Horizontal" Width="400" Margin="10">
                                        <CheckBox></CheckBox>
                                        <TextBlock Text="{Binding pavalue}" ></TextBlock>
                                    </StackPanel>
                                </DataTemplate>
                            </local:TemplateSelectorPollPage.CheckBoxField>
                            <local:TemplateSelectorPollPage.CheckBoxTextField>
                                <DataTemplate>
                                    <StackPanel Orientation="Horizontal" Width="400" Margin="10">
                                        <CheckBox></CheckBox>
                                        <TextBox Text="{Binding pavalue}" ></TextBox>
                                    </StackPanel>
                                </DataTemplate>
                            </local:TemplateSelectorPollPage.CheckBoxTextField>
                        </local:TemplateSelectorPollPage>
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>

And I have two classes for implementing data template selector:

public abstract class TemplateSelectorBase : ContentControl
            {
                public virtual DataTemplate SelectTemplate(object item, DependencyObject container)
                {
                    return null;
                }
                protected override void OnContentChanged(object oldContent, object newContent)
                {
                    base.OnContentChanged(oldContent, newContent);
                    ContentTemplate = SelectTemplate(newContent, this);
                }
            }

public class TemplateSelectorPollPage : TemplateSelectorBase
        {
            public DataTemplate CheckBoxField { get; set; }

            public DataTemplate RadioButtonField {get;set;}

            public DataTemplate CheckBoxTextField { get; set; }

            public DataTemplate RadioButtonTextField { get; set; }

            public override DataTemplate SelectTemplate(object item, DependencyObject container)
            {
                var answer = item as Answer;
                if (answer != null)
                {
                    var question = DataAccess.UtilsAccessDb.PpaDataAccessLib.Instance.RowsGet<Question>().Where(x => x.pqid == answer.pqid).FirstOrDefault();

                    if (question != null)
                    {
                        return question.pqtype == 1
                                   ? (answer.patype == 1 ? RadioButtonField : RadioButtonTextField)
                                   : (answer.patype == 1 ? CheckBoxField : CheckBoxTextField);
                    }
                }
                return base.SelectTemplate(item, container);
            }
        }

Call binding at the OnNavigatedTo method

App.PollViewModel.LoadData(firstQuestion.pid, firstQuestion.pqid);
DataContext = App.PollViewModel;

When I run application, the listbox does not have any items.
What inncorrect in this code?

  • 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-05T06:28:50+00:00Added an answer on June 5, 2026 at 6:28 am

    You failed second binging.

    Just replace Content=”{Binding QuestionsCurrent.Answers} on Content=”{Binding}”

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

Sidebar

Related Questions

I have this code in MainPage.xaml: <controls:PivotItem Header=first> <ListBox x:Name=MyListBox Margin=0,0,-12,0 ItemsSource={Binding ListBoxItem}> <ListBox.ItemTemplate>
I have this code in a xaml page: <ListBox Height=524 HorizontalAlignment=Left Margin=12,6,0,0 Name=listBox1 VerticalAlignment=Top
can someone give the C# equivalent of this xamle code? <ListBox Width=400 Margin=10 ItemsSource={Binding
I have a xaml file with this code: <GridViewColumn x:Name=lvCol3 Header=Quantità Width=120> <GridViewColumn.CellTemplate> <DataTemplate>
I currently have this XAML Code: <ListView x:Name=listFeedSearch Margin=-548.856,95.333,0,7.667 HorizontalAlignment=Left Width=542.5 RenderTransformOrigin=0.5,0.5 ItemsSource={Binding SearchCollection}>
I have this code in my xaml <local:MyDataSource x:Key=MyData /> <CollectionViewSource x:Key=ViewSource Source={Binding Source={StaticResource
Scenario: Currently I have this XAML code: <Button Content=_Cancel IsCancel=True Command={Binding Path=CancelCommand} Margin=5> <Button.ContentTemplate>
I have this code in a xaml file now in a event handler code
In a wpf project I have this XAML code <Window xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml xmlns:d=http://schemas.microsoft.com/expression/blend/2008 xmlns:mc=http://schemas.openxmlformats.org/markup-compatibility/2006
Let's say we have a XAML code like this: <Style TargetType={x:Type ListBoxItem}> <Setter Property=Template>

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.