Click here to Skip to main content
15,891,513 members
Home / Discussions / WPF
   

WPF

 
GeneralRe: M-V-VM implementation question Pin
ml_black22-May-09 4:14
ml_black22-May-09 4:14 
Questionprogramming html in wpf using c# Pin
ramakrishnamakkena21-May-09 2:40
ramakrishnamakkena21-May-09 2:40 
AnswerRe: programming html in wpf using c# Pin
Pete O'Hanlon21-May-09 4:32
mvePete O'Hanlon21-May-09 4:32 
QuestionListViewItem promblem Pin
mildred-frontfree21-May-09 0:57
mildred-frontfree21-May-09 0:57 
AnswerRe: ListViewItem promblem Pin
ABitSmart21-May-09 5:13
ABitSmart21-May-09 5:13 
GeneralRe: ListViewItem promblem Pin
mildred-frontfree21-May-09 18:14
mildred-frontfree21-May-09 18:14 
GeneralRe: ListViewItem promblem Pin
ABitSmart21-May-09 18:26
ABitSmart21-May-09 18:26 
AnswerRe: ListViewItem promblem Pin
Niladri_Biswas13-Jun-09 3:17
Niladri_Biswas13-Jun-09 3:17 
Alternatively you can use Ivalue Convertor for doing this

Xaml code:

<Window x:Class="AgeConvertor.Window2"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:AgeConvertor"   
    Title="Window2" Height="300" Width="300">
    <Window.Resources>

        <local:MyConverter x:Key="int2color" />

    </Window.Resources>
    <Grid>
        <ListBox ItemsSource="{Binding MultipleCountryList}"  Height="73" VerticalAlignment="Top">
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <TextBlock Text="{Binding CountryName}"
                 Background="{Binding Converter={StaticResource int2color}}"/>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>
    </Grid>
</Window>



.CS of Xaml

public partial class Window2 : Window
    {
        Person p = new Person();

        public Window2()
        {
            InitializeComponent();

            this.DataContext = p;

            p.LoadCountry();
        }
    }


ViewModel
public class Person:INotifyPropertyChanged 
    {
        

        DataSource _objDataSource = new DataSource();
        private ObservableCollection<Country> _countrycombo = new ObservableCollection<Country>();
        

        public void LoadCountry()
        {
            _countrycombo = new ObservableCollection<Country>(_objDataSource.CountryList());
          

        }

        public ObservableCollection<Country> MultipleCountryList
        {
            get
            {
                return _countrycombo;
            }
        }       

        #region INotifyPropertyChanged Members

        public event PropertyChangedEventHandler PropertyChanged;

        #endregion

        #region General Propertychange methods

        /// <summary>
        /// Called when [property changed].
        /// </summary>
        /// <param name="PropertyName">Name of the property.</param>
        protected void OnPropertyChanged(string PropertyName)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(PropertyName));
            }
        }

        #endregion
    }


ConvertorClass
public class MyConverter : IValueConverter
    {
        #region IValueConverter Members

        public object Convert(object value, Type targetType,
           object parameter, System.Globalization.CultureInfo culture)
        {

            int i = ((Country)value).A;
            return i % 2 == 0 ? Brushes.Red : Brushes.Green;

            //if (!(value is int))
            //    return null;
            //int i = (int)value;
            //return i % 2 == 0 ? Brushes.Red : Brushes.Green;
        }

        public object ConvertBack(object value, Type targetType,
               object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }

        #endregion
    }



The CountryEntity class
public class Country
    {
       
        public string _countryname = string.Empty;
        
        public string CountryName
        {
            get
            {
                return _countryname;
            }
            set
            {
                _countryname = value;
            }
        }
    }



The Model/DataSource

public class DataSource
    {
        ObservableCollection<Country> _country = new ObservableCollection<Country>();

        public ObservableCollection<Country> CountryList()
        {
            _country.Clear();
            CountryData();
            return _country;
        }

        private void CountryData()
        {
            _country.Add(new Country {A=1, CountryName = "India" });
            _country.Add(new Country { A = 2, CountryName = "USA" });
            _country.Add(new Country { A = 3, CountryName = "Canada" });
            _country.Add(new Country { A = 4, CountryName = "Singapore" });
        }
    }


Niladri Biswas

GeneralRe: ListViewItem promblem Pin
mildred-frontfree16-Jun-09 14:56
mildred-frontfree16-Jun-09 14:56 
GeneralRe: ListViewItem promblem Pin
Niladri_Biswas17-Jun-09 21:13
Niladri_Biswas17-Jun-09 21:13 
QuestionHelp getting values from combobox and comparing them to items in stackpanel Pin
Member 422055221-May-09 0:45
Member 422055221-May-09 0:45 
QuestionScrollViewer - How To Determine End of Scroll [SOLVED] Pin
#realJSOP21-May-09 0:32
mve#realJSOP21-May-09 0:32 
AnswerRe: ScrollViewer - How To Determine End of Scroll Pin
Pete O'Hanlon22-May-09 0:52
mvePete O'Hanlon22-May-09 0:52 
GeneralRe: ScrollViewer - How To Determine End of Scroll Pin
#realJSOP22-May-09 8:54
mve#realJSOP22-May-09 8:54 
GeneralRe: ScrollViewer - How To Determine End of Scroll Pin
#realJSOP1-Jun-09 11:09
mve#realJSOP1-Jun-09 11:09 
QuestionNo get device context Pin
krishnan.s20-May-09 15:26
krishnan.s20-May-09 15:26 
AnswerRe: No get device context Pin
Mark Salsbery20-May-09 15:49
Mark Salsbery20-May-09 15:49 
GeneralRe: No get device context Pin
krishnan.s21-May-09 0:22
krishnan.s21-May-09 0:22 
GeneralRe: No get device context Pin
Mark Salsbery21-May-09 5:45
Mark Salsbery21-May-09 5:45 
QuestionGettting metadata from TIFF file fails Pin
fjparisIII20-May-09 12:09
fjparisIII20-May-09 12:09 
AnswerRe: Gettting metadata from TIFF file fails Pin
Mark Salsbery20-May-09 15:45
Mark Salsbery20-May-09 15:45 
GeneralRe: Gettting metadata from TIFF file fails (RESOLVED!) Pin
fjparisIII20-May-09 16:46
fjparisIII20-May-09 16:46 
GeneralRe: Gettting metadata from TIFF file fails (RESOLVED!) Pin
Mark Salsbery20-May-09 17:15
Mark Salsbery20-May-09 17:15 
GeneralRe: Gettting metadata from TIFF file fails (RESOLVED!) Pin
fjparisIII21-May-09 12:33
fjparisIII21-May-09 12:33 
QuestionMessage Removed Pin
20-May-09 4:15
professionalN_tro_P20-May-09 4:15 

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.