Click here to Skip to main content
15,888,733 members
Home / Discussions / WPF
   

WPF

 
QuestionChange 3 variables in another WPF window Pin
GiuseppeKoll9-Feb-13 22:38
GiuseppeKoll9-Feb-13 22:38 
AnswerRe: Change 3 variables in another WPF window Pin
Mycroft Holmes10-Feb-13 9:02
professionalMycroft Holmes10-Feb-13 9:02 
GeneralRe: Change 3 variables in another WPF window Pin
GiuseppeKoll10-Feb-13 9:40
GiuseppeKoll10-Feb-13 9:40 
QuestionExpose Enum From Template Pin
Kevin Marois9-Feb-13 12:10
professionalKevin Marois9-Feb-13 12:10 
AnswerRe: Expose Enum From Template Pin
SledgeHammer019-Feb-13 13:43
SledgeHammer019-Feb-13 13:43 
QuestionData Flow in a WPF App Pin
AeroClassics9-Feb-13 11:19
professionalAeroClassics9-Feb-13 11:19 
AnswerRe: Data Flow in a WPF App Pin
Super Lloyd14-Feb-13 18:08
Super Lloyd14-Feb-13 18:08 
QuestionBinding DataGrid Pin
Sawyer19889-Feb-13 3:33
Sawyer19889-Feb-13 3:33 
Explain why the method works so crooked add to the collection and display DataGrid.Ispolzuyu binding in XAML

XML
<Window x:Class="bild.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:sys="clr-namespace:bild"
        Title="MainWindow" Height="519" Width="525">
    <Window.Resources>
        <sys:ViewModel x:Key="DataSource"/>        
    </Window.Resources>
 
        <Grid>
        <ListBox ItemsSource="{Binding Source={StaticResource DataSource}, Path=Persons}" 
                 DisplayMemberPath="Name"                 
            HorizontalAlignment="Left" Margin="49,21,0,201" Name="listBox1" Width="425" />
        <Grid DataContext="{Binding Source={StaticResource DataSource}}" Height="149" HorizontalAlignment="Left" Margin="49,134,0,0" Name="grid1" VerticalAlignment="Top" Width="425">
            <DataGrid 
                ItemsSource="{Binding Source={StaticResource DataSource}, Path=Persons}" 
                AutoGenerateColumns="False" Height="143" HorizontalAlignment="Left" Margin="36,0,0,0" Name="dataGrid1" VerticalAlignment="Top" Width="383" >
                <DataGrid.Columns>
                    <DataGridTextColumn Binding="{Binding Age}"  Header="Age" ></DataGridTextColumn>
                </DataGrid.Columns>
            </DataGrid>
        </Grid>
        <Button Content="Button" Height="23" HorizontalAlignment="Left" Margin="296,290,0,0" Name="button1" VerticalAlignment="Top" Width="75" Click="button1_Click" />
    </Grid>
</Window>


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;
 
namespace bild
{   
    public partial class MainWindow : Window
    {
        
        public MainWindow()
        {
            InitializeComponent();
        }
 
        private void button1_Click(object sender, RoutedEventArgs e)
        {
            ViewModel r = new ViewModel();
            r.ad();
            dataGrid1.ItemsSource = r.Persons;
        }
    }
    public class ViewModel
    {
        public ViewModel()
        {
            this.Persons = new ObservableCollection<Person>();
            this.Persons.Add(new Person("Ivan", 23));
            this.Persons.Add(new Person("Stefan", 34));
            this.Persons.Add(new Person("Maria", 16));
            this.Persons.Add(new Person("Michael", 78));
            
        }
        public void ad()
        {
           this.Persons = new ObservableCollection<Person>();
            this.Persons.Add(new Person("Maria", 16));
            this.Persons.Add(new Person("Michael", 78));
          
        }
 
        public ObservableCollection<Person> Persons
        {
            get;
            set;
        }
    }
    public class Person
    {
        public Person(string name, int age)
        {
            this.Name = name;
            this.Age = age;
        }
        public string Name
        {
            get;
            set;
        }
        public int Age
        {
            get;
            set;
        }
    }
}

AnswerRe: Binding DataGrid Pin
Andy41128-Feb-13 2:25
Andy41128-Feb-13 2:25 
QuestionMain Widow Appears on top of the Navigated Window In WPF Navigation Service Pin
Vimalsoft(Pty) Ltd6-Feb-13 0:43
professionalVimalsoft(Pty) Ltd6-Feb-13 0:43 
QuestionOpening new WPF form in seperate thread. Pin
Hema Bairavan2-Feb-13 8:31
Hema Bairavan2-Feb-13 8:31 
AnswerRe: Opening new WPF form in seperate thread. Pin
SledgeHammer012-Feb-13 10:28
SledgeHammer012-Feb-13 10:28 
GeneralRe: Opening new WPF form in seperate thread. Pin
Hema Bairavan3-Feb-13 2:57
Hema Bairavan3-Feb-13 2:57 
GeneralRe: Opening new WPF form in seperate thread. Pin
SledgeHammer013-Feb-13 7:41
SledgeHammer013-Feb-13 7:41 
GeneralRe: Opening new WPF form in seperate thread. Pin
Jason Gleim1-Mar-13 8:00
professionalJason Gleim1-Mar-13 8:00 
QuestionHow to user control view open in center of main parent window ? Pin
rahul ameta2-Feb-13 1:56
rahul ameta2-Feb-13 1:56 
Questionarrange elements inside wpf Pin
Remix Mixdox1-Feb-13 22:27
Remix Mixdox1-Feb-13 22:27 
AnswerRe: arrange elements inside wpf Pin
Abhinav S3-Feb-13 7:02
Abhinav S3-Feb-13 7:02 
QuestionCustom Controls Pin
Sawyer19881-Feb-13 7:05
Sawyer19881-Feb-13 7:05 
QuestionApplication Launcher Pin
Mycroft Holmes31-Jan-13 13:49
professionalMycroft Holmes31-Jan-13 13:49 
AnswerRe: Application Launcher Pin
Abhinav S1-Feb-13 8:22
Abhinav S1-Feb-13 8:22 
QuestionWPF controls refresh Pin
caradri31-Jan-13 1:50
caradri31-Jan-13 1:50 
AnswerRe: WPF controls refresh Pin
Pete O'Hanlon31-Jan-13 2:44
mvePete O'Hanlon31-Jan-13 2:44 
GeneralRe: WPF controls refresh Pin
caradri31-Jan-13 10:20
caradri31-Jan-13 10:20 
GeneralRe: WPF controls refresh Pin
Richard Deeming31-Jan-13 11:25
mveRichard Deeming31-Jan-13 11:25 

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.