TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Sebastian
NA
1
1.6k
Listbox, DepedencyProperty, primary questions
Dec 13 2012 3:05 PM
Hello, I've started to programming Aplplications in WPF and I have very simple questions, because I don't understand most of courses in the Internet.
1. What is DependencyProperty and how can I use it for example - it is to change parameters in XAML code ?
2. I have some Listboxes and I'd like to add some entires to list by this application - how can I do it ?
XAML:
<Window x:Class="WpfApplication1.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>
<StackPanel x:Name="sp_gridcolumn1" Grid.Column="1">
<ListBox Name="listboks" ItemsSource="{Binding lista}">
<ListBox.ItemTemplate>
<DataTemplate>
<Grid>
<TextBlock Text="{Binding imie}" Grid.Column="0"/>
<TextBlock Text="{Binding nazwisko}" Grid.Column="1"/>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="100" />
<ColumnDefinition Width="100" />
</Grid.ColumnDefinitions>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Vertical"
Background="Beige">
</StackPanel>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
</ListBox>
</StackPanel>
<StackPanel Grid.Column="0" VerticalAlignment="Center" HorizontalAlignment="Center">
<Label>
Imie
</Label>
<TextBox Name="imiee" Margin="0 5" >
</TextBox>
<Label>
Nazwisko
</Label>
<TextBox Name="nazwiskoo" Margin="0 5">
</TextBox>
<Button Click="add" Height="30" Width="100">
Dodaj
</Button>
<Button Click="remove" Height="30" Width="100" Margin="5">
remove
</Button>
<Button Click="clear" Height="30" Width="100">
clear
</Button>
<Button Click="exit" Height="30" Width="100" Margin="0 10">
exit
</Button>
</StackPanel>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="150" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
</Grid>
</Window>
C# code:
using System;
using System.Collections.Generic;
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 WpfApplication1
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
CompositeCollection[] lista = new CompositeCollection[]
{
new CompositeCollection{imie = "Janusz", nazwisko = "Nowak"},
new CompositeCollection{imie = "Jan", nazwisko = "Kowalski"}
};
public MainWindow()
{
InitializeComponent();
listboks.ItemsSource = lista;
}
private void dodaj(object sender, RoutedEventArgs e)
{
if ((imiee.Text != "") && (nazwiskoo.Text != ""))
{
listboks.Items.Add(imiee.Text);
listboks.Items.Add(nazwiskoo.Text);
}
else MessageBox.Show("Podaj imie oraz nazwisko!");
}
private void clear(object sender, RoutedEventArgs e)
{
listboks.ItemsSource.GetHashCode();
}
private void exit(object sender, RoutedEventArgs e)
{
this.Close();
}
private void remove(object sender, RoutedEventArgs e)
{
}
}
class CompositeCollection
{
public string imie
{
get;
set;
}
public string nazwisko
{
get;
set;
}
}
}
Please, give me only simple examples
Thanks.
Reply
Answers (
0
)
I got “System.Collections.Generic.List” instead of data
Move Item from bound Listbox to another bound Listbox