Skip to content

Instantly share code, notes, and snippets.

@OmerRaviv
Last active August 29, 2015 14:25
Show Gist options
  • Save OmerRaviv/0dd8db462c1299f9cc2e to your computer and use it in GitHub Desktop.
Save OmerRaviv/0dd8db462c1299f9cc2e to your computer and use it in GitHub Desktop.
-----
MainWindow.xaml.cs:
-----
class Person
{
public int Age { get; set; }
}
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
DataContext = new ObservableCollection<Person>(Enumerable.Range(1,1000).Select(i => new Person {Age=i})) ;
}
}
-----
MainWindow.xaml:
-----
<Window x:Class="WpfApplication5.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:wpfApplication5="clr-namespace:WpfApplication5"
Title="MainWindow" Height="350" Width="525">
<Grid>
<ItemsControl ItemsSource="{Binding}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<wpfApplication5:MyUserControl/>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</Grid>
</Window>
-----
MyUserControl.xaml:
-----
<UserControl x:Class="WpfApplication5.MyUserControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:calcBinding="clr-namespace:CalcBinding;assembly=CalcBinding"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<Grid>
<!-- Uncomment the next line to see that without CalcBinding, this runs a lot faster. -->
<TextBlock Text="{calcBinding:Binding Path=Age*2}" FontSize="1"/>
<TextBlock Text="{Binding Path=Age}" FontSize="1"/>
</Grid>
</UserControl>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment