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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T21:04:09+00:00 2026-06-01T21:04:09+00:00

I’ve just recently started working on an app that displays a bunch of xml

  • 0

I’ve just recently started working on an app that displays a bunch of xml data in a listBox, but the problem is not every xml item has a child value (In my problem, upload), so its listBox code shouldn’t be displayed.

Example:

<item>
     <id>1</id>
     <body>Some text</body>
     <upload></upload>
     <created>Some text</created>
</item>

I’m getting the data and populating my list this way:

var data = from query in loadedData.Descendants("item")
                   select new droppedItem
                   {
                       Id = (int)query.Element("id"),
                       Body = (string)query.Element("body"),
                       Upload = (string)query.Element("upload"),
                       Created = (DateTime)ConvertFromUnixTimestamp((double)query.Element("created"))
                   };
        userDrops.ItemsSource = data;

And my xaml looks like:

<ListBox Margin="0,0,-12,0" Name="userDrops">
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <StackPanel Margin="0,0,0,17" Width="432">
                            <RichTextBox>
                                <Paragraph>
                                    <Run Text="{Binding Body}" FontSize="25" FontFamily="Segoe WP"></Run>
                                </Paragraph>
                                <Paragraph>
                                    <Hyperlink NavigateUri="{Binding Upload}" TargetName="_blank" FontSize="25" FontFamily="Segoe WP">{Binding Upload}</Hyperlink>
                                </Paragraph>
                                <Paragraph>
                                    <Run Text="{Binding Created}" FontFamily="Segoe WP SemiLight"></Run>
                                </Paragraph>
                            </RichTextBox>
                        </StackPanel>
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>

What I want to do is only display the paragraph holding the upload info if the xml upload child holds a value. Otherwise, just remove it from the listBox. I can’t figure out how to change the basic listBox template though.

Any help would be great!

  • 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-01T21:04:11+00:00Added an answer on June 1, 2026 at 9:04 pm

    How about using TextBlocks to display Body and Created? The middle part would be a RichTextBox, you can use a Visibility converter to toggle hide/show if Upload is empty.

    You need to include your converter in your xaml page first,

    xmlns:converters="clr-namespace:xxx.Converters;assembly=xxx"
    
    <converters:VisibilityConverter x:Key="visibilityConverter" />
    

    then use it inside your template,

                    <StackPanel Margin="40,237,8,326" Width="432" Grid.Row="1"> 
                        <RichTextBox> 
                            <Paragraph> 
                                <Run Text="{Binding Body}" FontSize="25" FontFamily="Segoe WP"></Run> 
                            </Paragraph>
                        </RichTextBox> 
                        <RichTextBox Visibility="{Binding Upload, Converter={StaticResource VisibilityConverter}}">
                            <Paragraph> 
                                <Hyperlink NavigateUri="{Binding Upload}" TargetName="_blank" FontSize="25" FontFamily="Segoe WP">{Binding Upload}</Hyperlink> 
                            </Paragraph>
                        </RichTextBox> 
                            <TextBlock Text="{Binding Created}" FontFamily="Segoe WP SemiLight"/>
                    </StackPanel>
    

    The converter should be something like this,

      public class VisibilityConverter : IValueConverter
        {
            public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
            {
                bool visible = true;
    
                if (value is bool)
                {
                    visible = (bool)value;
                }
                else if (value is int || value is short || value is long)
                {
                    visible = 0 != (int)value;
                }
                else if (value is float || value is double)
                {
                    visible = 0.0 != (double)value;
                }
                else if (value is string) {
                    visible = ((string)value).Length > 0;
                }
                else if (value == null) {
                    visible = false;
                }
    
                if ((string)parameter == "!")
                {
                    visible = !visible;
                }
    
                return visible ? Visibility.Visible : Visibility.Collapsed;
            }
    
            public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
            {
                throw new NotImplementedException();
            }
        }
    

    For more info regarding value converter, see this.

    UPDATE

    In your App.xaml, do this,

    <Application xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
                 xmlns:sg="http://schemas.stargategroup.com.au/2010/xaml/presentation" 
                 xmlns:converters="clr-namespace:xxx.Converters"
                 x:Class="xxx.Application.App">
    
        <Application.Resources>
            <ResourceDictionary>
                <converters:VisibilityConverter x:Key="VisibilityConverter" />
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need a function that will clean a strings' special characters. I do NOT
I want to construct a data frame in an Rcpp function, but when I
I'm parsing an XML file, the creators of it stuck in a bunch social
I have just tried to save a simple *.rtf file with some websites and
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but

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.