Directory Freebies VS CheatSheet Forum

RSS

Email

Translate

Home About Archive Privacy Contact Advertise Write for Dev102
Posted by Amit on Apr 2nd, 2009 | Filed under .Net, WPF | 5 Comments

Hi

 

Here is a problem that one of my colleagues who is just starting to use WPF got himself into. He was working on an application that displays items using an ItemsControl and uses a DataTemplate. Inside the DataTemplate he used an Image. Here is the Xaml code:

 

   1: <Window.Resources>
   2:         <Image Source="Creek.jpg" x:Key="IMG"></Image>
   3:     </Window.Resources>
   4:     <Grid>
   5:         <ItemsControl ItemsSource="{Binding}">
   6:             <ItemsControl.ItemTemplate>
   7:                 <DataTemplate>
   8:                     <Border BorderThickness="2" BorderBrush="Black" 
   9:                             CornerRadius="3" MinHeight="10">
  10:                         <ContentControl Content="{StaticResource IMG}"/>
  11:                     </Border>
  12:                 </DataTemplate>
  13:             </ItemsControl.ItemTemplate>
  14:         </ItemsControl>
  15:     </Grid>

This is a much simpler example, but the principal is the same.

 

Can you see what was he doing wrong?


Continue Reading...

Hi

 

In my latest article I discussed Scrolling and Binding to large collections in WPF. We saw some disturbing behavior when binding a large collection to an ItemsControl. After Further Examination I found out very interesting things regarding that matter.

 

Memory Consumption

 

We saw that the application used about 500MB of Ram. Lets look at the code again:


Continue Reading...
Posted by Amit on Jun 13th, 2008 | Filed under .Net, WPF | 2 Comments

We have all used WPF DataTemplates, but I bet most of you never gave thought to the meaning of the x:Key attribute. We all know the meaning of the DataType attribute, which determines to what type of data the template will apply to. But what about the x:Key why is it there? Lets tale a look at the following code:

<Window.Resources>
        <DataTemplate DataType="{x:Type data:s}">
            <Button Width="50" Height="50">
                <TextBlock Text="{Binding text}"></TextBlock>
            </Button>
        </DataTemplate>
    </Window.Resources>
    <Canvas>
        <ItemsControl ItemsSource="{Binding}">
        </ItemsControl>
    </Canvas>

Continue Reading...

Often we want to display a list of elements and allow the user to sort them in various ways. There are many ways to do it and I wanted to show you how to use a SortDescription Object. What is a SortDescription object you ask? It receives two parameters in its constructor: the first is [...]


Continue Reading...
Write Article for Dev102

Write for Dev102!

We pay for user submitted tutorials and articles that we publish. Anyone can send in a contribution

Learn More