Click here to Skip to main content
15,898,134 members
Home / Discussions / WPF
   

WPF

 
AnswerRe: Wpf Pin
Abhinav S1-Sep-11 21:17
Abhinav S1-Sep-11 21:17 
GeneralRe: Wpf Pin
radhika 51-Sep-11 21:23
radhika 51-Sep-11 21:23 
GeneralRe: Wpf Pin
Saksida Bojan9-Sep-11 23:45
Saksida Bojan9-Sep-11 23:45 
QuestionSwitch between diffrent languages with indexers Pin
Mc_Topaz31-Aug-11 21:37
Mc_Topaz31-Aug-11 21:37 
AnswerRe: Switch between diffrent languages with indexers Pin
Wayne Gaylard31-Aug-11 23:13
professionalWayne Gaylard31-Aug-11 23:13 
GeneralRe: Switch between diffrent languages with indexers Pin
Mc_Topaz31-Aug-11 23:36
Mc_Topaz31-Aug-11 23:36 
GeneralRe: Switch between diffrent languages with indexers Pin
Wayne Gaylard31-Aug-11 23:40
professionalWayne Gaylard31-Aug-11 23:40 
GeneralRe: Switch between diffrent languages with indexers Pin
Mc_Topaz1-Sep-11 1:57
Mc_Topaz1-Sep-11 1:57 
Still nothing happens. I must be missing something. Here is the entire code:
C#
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.ComponentModel;
using System.IO;

namespace SwitchLanguage
{
    public partial class MainWindow : Window, INotifyPropertyChanged
    {
        string folderPath = @"C:\Users\SwitchLanguage\";
        ObservableCollection<LanguageItem> words;
        public event PropertyChangedEventHandler PropertyChanged;

        public MainWindow()
        {
            InitializeComponent();

            // Must instance event or else PropertyChanged is ALWAYS null
            PropertyChanged += new PropertyChangedEventHandler(MainWindow_PropertyChanged);
        }


        private void btnUK_Click(object sender, RoutedEventArgs e)
        {
            ReadFile("UK.txt");
        }

        private void btnUS_Click(object sender, RoutedEventArgs e)
        {
            ReadFile("US.txt");
        }



        private void ReadFile(string file)
        {
            if (!File.Exists(folderPath + file))
            {
                throw new FileNotFoundException("Language file doesn't exist");
            }

            StreamReader sr = new StreamReader(folderPath + file);
            ObservableCollection<LanguageItem> words = new ObservableCollection<LanguageItem>();

            while (!sr.EndOfStream)
            {
                string[] parts = sr.ReadLine().Split('=');

                LanguageItem languageItem = new LanguageItem();
                languageItem.ID = int.Parse(parts[0]);
                languageItem.Word = parts[1];
                words.Add(languageItem);
            }

            Words = words;

            sr.Close();
        }

        public ObservableCollection<LanguageItem> Words
        {
            get { return words; }
            set
            {
                if (words != value)
                {
                    words = value;
                    PropertyChanged(this, new PropertyChangedEventArgs("Words"));
                }
            }
        }

        void MainWindow_PropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            Console.WriteLine("");
        }
    }

    public class LanguageItem
    {
        public int ID { get; set; }
        public string Word { get; set; }
    }
}
XML
<Window x:Class="SwitchLanguage.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
        <Label Name="lblWord" Content="{Binding Path=Words[0].Word}" Margin="50,-100,0,0" Width="200" Height="30"></Label>
        <Button Width="100" Height="40" Click="btnUK_Click" Content="UK" Margin="-100,0,0,0"></Button>
        <Button Width="100" Height="40" Click="btnUS_Click" Content="US" Margin="100,0,0,0"></Button>
    </Grid>
</Window>

GeneralRe: Switch between diffrent languages with indexers Pin
Pete O'Hanlon1-Sep-11 2:09
mvePete O'Hanlon1-Sep-11 2:09 
GeneralRe: Switch between diffrent languages with indexers Pin
Mc_Topaz1-Sep-11 2:23
Mc_Topaz1-Sep-11 2:23 
GeneralRe: Switch between diffrent languages with indexers Pin
Pete O'Hanlon1-Sep-11 3:27
mvePete O'Hanlon1-Sep-11 3:27 
GeneralRe: Switch between different languages with indexers Pin
Wayne Gaylard1-Sep-11 21:50
professionalWayne Gaylard1-Sep-11 21:50 
GeneralRe: Switch between different languages with indexers Pin
Pete O'Hanlon1-Sep-11 22:27
mvePete O'Hanlon1-Sep-11 22:27 
GeneralRe: Switch between different languages with indexers Pin
Wayne Gaylard1-Sep-11 23:05
professionalWayne Gaylard1-Sep-11 23:05 
GeneralRe: Switch between different languages with indexers Pin
Pete O'Hanlon1-Sep-11 23:29
mvePete O'Hanlon1-Sep-11 23:29 
GeneralRe: Switch between different languages with indexers Pin
Mycroft Holmes1-Sep-11 23:45
professionalMycroft Holmes1-Sep-11 23:45 
GeneralRe: Switch between diffrent languages with indexers Pin
Wayne Gaylard1-Sep-11 2:39
professionalWayne Gaylard1-Sep-11 2:39 
AnswerRe: Switch between diffrent languages with indexers Pin
Abhinav S1-Sep-11 1:13
Abhinav S1-Sep-11 1:13 
Questionsilverlight - backgroundworker process [modified] Pin
arkiboys31-Aug-11 18:41
arkiboys31-Aug-11 18:41 
AnswerRe: silverlight - backgroundworker process Pin
Mycroft Holmes31-Aug-11 19:28
professionalMycroft Holmes31-Aug-11 19:28 
GeneralRe: silverlight - backgroundworker process Pin
arkiboys31-Aug-11 19:30
arkiboys31-Aug-11 19:30 
AnswerRe: silverlight - backgroundworker process Pin
Pete O'Hanlon31-Aug-11 21:07
mvePete O'Hanlon31-Aug-11 21:07 
GeneralRe: silverlight - backgroundworker process Pin
arkiboys31-Aug-11 22:11
arkiboys31-Aug-11 22:11 
GeneralRe: silverlight - backgroundworker process Pin
Pete O'Hanlon31-Aug-11 23:18
mvePete O'Hanlon31-Aug-11 23:18 
GeneralRe: silverlight - backgroundworker process Pin
arkiboys31-Aug-11 23:38
arkiboys31-Aug-11 23:38 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.