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

  • Home
  • SEARCH
  • 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 8450837
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T11:05:06+00:00 2026-06-10T11:05:06+00:00

XAML: <ListBox> <ListBox.ItemTemplate> <DataTemplate > <StackPanel > <Grid Width=335 > <TextBlock Text={Binding Body} />

  • 0

XAML:

<ListBox>
    <ListBox.ItemTemplate>
        <DataTemplate >  
            <StackPanel >
                <Grid  Width="335"  >
                    <TextBlock Text="{Binding Body}"  />
                </Grid>
            </StackPanel>
        </DataTemplate>
        <DataTemplate > 
            <StackPanel >
                <Grid  Width="335"  >
                    <Image  Source="{Binding Image}"  />
                </Grid>
            </StackPanel>
        </DataTemplate>
    </ListBox.ItemTemplate>
</ListBox>

CS:

public class GardenConverter : ContentControl
{
    public DataTemplate TextTemplate { get; set; }
    public DataTemplate ImageTemplate { get; set; }

    protected override void OnContentChanged(object oldContent, object newContent)
    {
        base.OnContentChanged(oldContent, newContent);
        // apply the required template

        GardenObject garden = newContent as GardenObject;
        if (garden.image == "0")
        {
            ContentTemplate = TextTemplate;
        }
        else
        {
            ContentTemplate = ImageTemplate;
        }
    }
}
  • 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-10T11:05:08+00:00Added an answer on June 10, 2026 at 11:05 am

    You might try a data template selector.

    public class GardenTemplateSelector : DataTemplateSelector
    {
        public override DataTemplate SelectTemplate(object item, DependencyObject container)
        {
            var element = container as FrameworkElement;
            if (element != null && item != null && item is GardenObject)
            {   
                if((item as GardenObject).image == "0")
                {
                    return element.FindResource("TextTemplate") as DataTemplate;            
                }
                else
                {
                    return element.FindResource("ItemTemplate") as DataTemplate;            
                }           
            }
    
            return null;
        }
    }
    

    In XAML you would need to define the TextTemplate and ItemTemplate.

    For more info, see http://msdn.microsoft.com/en-us/library/system.windows.controls.datatemplateselector.aspx

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

Sidebar

Related Questions

So I have this Xaml inside a ListBox Item Template: <ListBox.ItemTemplate> <DataTemplate> <Grid Height=22
I have the following XAML: <ListBox HorizontalAlignment=Left Margin=0,6,0,10 Name=listBox1 Width=468 ItemsSource={Binding} Grid.ColumnSpan=1> <ItemsControl.ItemTemplate> <DataTemplate>
Here's the XAML: <ListBox Grid.Row=1 x:Name=lstGames Background=#343434 > <ListBox.ItemTemplate> <DataTemplate> <Grid ShowGridLines=True> <Grid.ColumnDefinitions> <ColumnDefinition
this is my XAML of listbox <ListBox Height=100 Margin=12,12,8,0 Name=CategoriesList VerticalAlignment=Top> <ListBox.ItemTemplate> <DataTemplate> <StackPanel>
i have customized ListBox declared in XAML: <ListBox x:Name=uicMDSQonfServer> <ListBox.ItemTemplate> <DataTemplate> <StackPanel Orientation=Horizontal Margin=0,5,0,5>
I have a ListBox with the following XAML: <ListBox.ItemTemplate> <DataTemplate> <Grid Name=listItemGrid> <Grid.ColumnDefinitions> <ColumnDefinition
I have a listbox defined in XAML as: <ListBox x:Name=directoryList MinHeight=100 Grid.Row=0 ItemsSource={Binding Path=SelectedDirectories}/>
I have a ListBox which has StackPanel s holding a TextBlock and an Image
This is my XAML so far. <ScrollViewer Grid.Column="1" Grid.RowSpan="2"> <ListBox Background="Black" ItemsSource="{Binding Path=ActiveLog}" >
I have a templated ListBox : <ListBox Grid.Row=0 Grid.Column=1 Background=Transparent BorderThickness=0 x:Name=mainMenu ItemsSource={Binding Source={x:Static

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.