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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T22:46:43+00:00 2026-06-11T22:46:43+00:00

I am trying to bind data from text files (and the names of those

  • 0

I am trying to bind data from text files (and the names of those files) to a ListBox in a C# Metro style app.

I’ve checked out the Metro Samples – I haven’t been able to make too much sense out of them though. I’m relatively new to XAML to begin with, and throwing that ontop of Metro-style apps just adds to the confusion.

For something that is such a trivial task in WinForms, it feels like I’m trying to write my own OS!

Can someone please help me out a little? I’ve searched and searched but I just end up finding the same old tutorials/documentation; and maybe it’s just me, but I feel that the documentation is lacking in this area. Maybe it’s just not complete yet?

Any help at all will be much appreciated 🙂

  • 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-11T22:46:44+00:00Added an answer on June 11, 2026 at 10:46 pm

    V declare a dictionary and loop through all your files adding the name as a key and the contents of the file as the value.

    In XAML then bind the listbox to the items in the dictionary and set the displaymemberpath to the key of the KeyValuePair.

    When selecting update the other control that will show your contents.
    I’ll look if i can make a example for you in code.

    Here the Example please do not look at the styling 🙂 Used MVVM for this
    My ViewModel

    namespace WPFTest.ViewModels
    {
    using System.IO;
    using System.Windows.Input;
    
    using Microsoft.Practices.Prism.Commands;
    
    public class MainViewModel : NotificationObject
    {
        public MainViewModel()
        {
            FileList = new Dictionary<string, string>();
            FillFileListCommand = new DelegateCommand(FillFileListExecuted);
        }
    
        private Dictionary<string, string> fileList;
    
        public Dictionary<string,string> FileList
        {
            get
            {
                return fileList;
            }
            set
            {
                fileList = value;
                RaisePropertyChanged(()=>FileList);
            }
        }
    
        public ICommand FillFileListCommand { get; set; }
        private void FillFileListExecuted()
        {
            var path = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
            var files = Directory.GetFiles(path, "*.txt");
            var dict = new Dictionary<string, string>();
            foreach (var file in files)
            {
                using (var reader = new StreamReader(file))
                {
                    var text = reader.ReadToEnd();
                    dict.Add(file, text);
                }
            }
            FileList = dict;
        }
    }
    

    }

    the xaml

    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="347*" />
            <RowDefinition Height="414*" />
        </Grid.RowDefinitions>
        <ListBox Height="701" Name="listBox1" Width="302" Margin="12,48,664,0" VerticalAlignment="Top" ItemsSource="{Binding FileList}" DisplayMemberPath="Key" Grid.RowSpan="2" />
        <TextBlock Height="737" HorizontalAlignment="Left" Margin="320,12,0,0" Name="textBlock1" Text="{Binding ElementName=listBox1, Path=SelectedItem.Value}" VerticalAlignment="Top" Width="646" TextWrapping="Wrap" Grid.RowSpan="2" />
        <Button Content="Fill" Height="30" HorizontalAlignment="Left" Margin="12,12,0,0" Name="button1" VerticalAlignment="Top" Width="302" Command="{Binding FillFileListCommand}" />
    </Grid>
    

    And in the codebehind of the xaml say

    DataContext = new MainViewModel();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to bind data from SQL to a repeater control. I have
I am trying to bind data from json. In the controller, I am sending
I am trying to bind(select) the some data by value from my list but
I'm trying to bind data from my SQLiteDatabase to a ListView . I'm currently
I am trying bind data from database into rich textbox here is my code:
Hi I'm trying to bind data to a kendochart, but no bars are appearing
I'm trying to bind a list of data to a data grid, but can't
I am trying to bind a model coming from the server over json to
I am trying to bind the Text of a TextBox named 'txtImage' to an
I am trying to bind an ArrayCollection result coming in from the server to

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.