Friday, October 2, 2009

Getting it to work

Found the courage again to code in this WPF world.
Reverted to use the ItemTemplate in the listbox, to get it to work. But now I have double XAML code : a datatemplate showing how a certain item is displayed, and a style showing how a certain item is displayed. The solution for this is to let the datatemplate use the style, so the layout is only defined once, like so :
<Style x:Key="IssueTemplate" >
<Setter Property="Control.Template">
<StackPanel Orientation="Horizontal" >
<Label Content="{Binding Key}" Width="200"/>
<Label Content="{Binding Description}" />
<Label Content="{Binding Votes}" />
<Label Content="{Binding Assignee}" />
<Label Content="{Binding Created}" />
<Label Content="{Binding Priority}" />
<Label Content="{Binding Reporter}" />
<Label Content="{Binding Status}" />
<Label Content="{Binding Votes}" />

<DataTemplate x:Key="IssueDataTemplate" >
<ContentControl Style="{StaticResource IssueTemplate}"/>
</DataTemplate >
The issue with the double click is not relevant anymore, I wanted to show a second window on double clicking an issue, but changed my mind. Now when you select an item in the listbox, the details of the selected issue are shown at the top of the screen. This is done by adding a ContentControl to the main window, binding its datacontext it to the same one as the listbox and setting the property IsSynchronizedWithCurrentItem to true. This works rather well. The code of the main window looks now like this :
<Expander VerticalContentAlignment="Top"
DataContext="{StaticResource CCNetProject}" >
<ContentControl Style="{StaticResource CCNetProjectTemplate}" />
<ContentControl DataContext="{StaticResource AllIssues}"
Style="{StaticResource IssueDetailTemplate}"
DockPanel.Dock="Top" />
<ListBox DockPanel.Dock="Bottom"
ItemsSource="{Binding Source={StaticResource AllIssues}}"
ItemTemplate="{StaticResource IssueDataTemplate}"

As you can see, there is nothing in the main window about how a certain item is displayed, no coloring, borders, ... All this is done is in the styles. I'll see how far I get with this approach. I'm now busy with showing the details of a certain issue, when that is done the most important functionality of the program is done, making it possible to give the app a more polished look.
Stay tuned ...

No comments:

Post a Comment