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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T09:20:08+00:00 2026-05-13T09:20:08+00:00

Basically I have a WPF application that will display announcements to the user within

  • 0

Basically I have a WPF application that will display announcements to the user within a listbox. The information that populates the list box comes from a XML file which contains details about different announcements. I am then applying a data template to display the relevant pieces of information. What I have is two buttons at the bottom of the application, what I want is when the user clicks on the unread announcements button that the data is filtered to only show the unread announcements in the listbox. Then when the user clicks on All announcements I want them to all be shown again. The data template that I’m using will remain the same whichever button is clicked.

In the XML file which is being used there is a field called read, with 0 indicating it hasn’t been read while 1 indicates that it has and this should be used to filter.

So really I’m just looking for examples of filtering or any good tutorials, so I can make some progress. If you require any of my code just let me know and I’ll paste it in.

EDIT

Now added code below to show how the data is bound and also the layout of the data:

<XmlDataProvider
                        x:Key="Article"
                        Source="/Data/People.xml"
                        XPath="People/article"/>
<DataTemplate x:Key="AnnouncementTemplate">
            <Border Background="#2200FF00" 
                            BorderBrush="Black" 
                            BorderThickness="1" 
                            CornerRadius="8"  
                            Margin="2,4,2,4" 
                            Padding="2"
                    >
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="30"/>
                        <ColumnDefinition Width="220"/>
                    </Grid.ColumnDefinitions>
                    <Border Background="#2200FF00" 
                            BorderBrush="Black" 
                            BorderThickness="1" 
                            CornerRadius="8"  
                            Margin="2,4,2,4" 
                            Padding="2"
                    >
                    <StackPanel Grid.Column="0">
                        <Image Stretch="Fill" Width="20" Source="Images/BlueOrb.ico" Height="20" VerticalAlignment="Center" HorizontalAlignment="Center"/>
                    </StackPanel>
                </Border>
                <StackPanel Grid.Column="1" Margin="5">
                    <StackPanel Orientation="Horizontal">
                        <TextBlock FontWeight="Bold" Text="{Binding XPath=./author}" />
                        <TextBlock Text=" "/>
                        <TextBlock Text="{Binding XPath=./datetime}" TextTrimming="WordEllipsis"/>
                    </StackPanel>
                    <StackPanel>
                        <TextBlock FontWeight="Bold" Text="{Binding XPath=./title}"/>
                    </StackPanel>
                    <StackPanel>
                        <TextBlock Text="{Binding XPath=./body}" TextTrimming="WordEllipsis"/>
                    </StackPanel>
                 </StackPanel>

                </Grid>
            </Border>
        </DataTemplate>

<ListBox Style="{StaticResource SpecialListStyle}"
                         Name="listBox1"
                         Margin="10,10,10,10"
                         Grid.Row="1"
                         ItemsSource="{Binding Source={StaticResource Article}}" 
                         IsSynchronizedWithCurrentItem="True"
                         ItemContainerStyle="{StaticResource SpecialListItem}"
                         ItemTemplate="{StaticResource AnnouncementTemplate}"/>

Example of the data held in the XML file, the data wants to be filtered so it only shows messages where read == 0

<People>
  <article>
    <author>Michael</author>
    <title>Happy Christmas</title>
    <body>Merry Christmas one and all</body>
    <priority>1</priority>
    <uid>G-0617-8567-EF32-hello</uid>
    <audience>0</audience>
    <read>0</read>
    <datetime>December 31, 2009 23:59:59</datetime>
  </article>
  <article>
    <author>Gary</author>
    <title>Landesk</title>
    <body>Landesk Distributed</body>
    <priority>0</priority>
    <uid>G-0618-8567-EF32-hello</uid>
    <audience>0</audience>
    <read>1</read>
    <datetime>December 31, 2009 23:59:59</datetime>
  </article>
</People>
  • 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-13T09:20:08+00:00Added an answer on May 13, 2026 at 9:20 am

    I’ve now been able to resolve this using the following code which also involved making the read node of the XML file into an attribute of the article element:

    ICollectionView RefineList()
        {
            DataSourceProvider provider = (DataSourceProvider)this.FindResource("Article");
            return CollectionViewSource.GetDefaultView(provider.Data);
        }
    
            private void Unread_Click(object sender, RoutedEventArgs e)
        {
            ICollectionView view = RefineList();
             if (view.Filter == null)
            {
                view.Filter = delegate(object item)
                {
                    return
                    int.Parse(((XmlElement)item).Attributes["read"].Value) == 0;
                };
            }
            else
            {
                view.Filter = null;
            }   
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 357k
  • Answers 357k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Anyway, i got it, its CentOS 5.4, in my box:… May 14, 2026 at 9:01 am
  • Editorial Team
    Editorial Team added an answer I reminded myself that I had xDebug installed on the… May 14, 2026 at 9:01 am
  • Editorial Team
    Editorial Team added an answer You can do something like this: var unsavedChanges = false;… May 14, 2026 at 9:01 am

Related Questions

I have these container objects (let's call them Container) in a list. Each of
Im trying to look into using the WPF WriteableBitmap class to allow my application
I am trying to use this function from a COM API which enables the
I have a mixed UI (Win App, WPF App, and soon an ASP.NET MVC
Related (but not a dupe!) to this question: Help with the WPF TextCompositionManager events

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.