ListView sizes bigger than Window - c#

I am filling a ListView in my WPF Application through a webserver.
Once the Data is loaded, the ListView exeeds the bounds of its parent container and scales to infinity and Scrolling is no longer possible.
I already tried to set the MaxHeigth to the parents ActualHeight, which does not return the expected result.
<TabItem x:Name="unassingedErrors" Header="{x:Static p:Resources.MainContentPageUnassingedErrors}">
<StackPanel>
<Separator Grid.Row="1"/>
<!--<Frame Grid.Row="2" Name="MainFrameError" Source="UnassignedErrorPage.xaml" />-->
<Grid>
<Grid.DataContext>
<vme:UnassignedErrorPageVM x:Name="ViewModel"/>
</Grid.DataContext>
<ScrollViewer>
<ListView ItemsSource="{Binding errorList}">
<ListView.Template>
<ControlTemplate>
<ItemsPresenter></ItemsPresenter>
</ControlTemplate>
</ListView.Template>
<ListView.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Label Grid.Row="0" Grid.Column="0" Content="{x:Static p:Resources.ErrorPageID}"/>
<Label Grid.Row="0" Grid.Column="1" Content="{x:Static p:Resources.ErrorPageText}"/>
<Label Grid.Row="0" Grid.Column="2" Content="{x:Static p:Resources.ErrorPageThrowDate}"/>
<Label Grid.Row="0" Grid.Column="3" Content="{x:Static p:Resources.ErrorPageHandledDate}"/>
<Label Grid.Row="0" Grid.Column="4" Content="{x:Static p:Resources.ErrorPageIncident}"/>
<Label Grid.Row="0" Grid.Column="5" Content="{x:Static p:Resources.ErrorPageType}"/>
<Label Grid.Row="0" Grid.Column="6" Content="{x:Static p:Resources.ErrorPageSensor}"/>
<Label Grid.Row="1" Grid.Column="0" Content="{Binding ID}"/>
<Label Grid.Row="1" Grid.Column="1" Content="{Binding Text}"/>
<Label Grid.Row="1" Grid.Column="2" Content="{Binding ThrowDate}"/>
<Label Grid.Row="1" Grid.Column="3" Content="{Binding HandledDate}"/>
<Label Grid.Row="1" Grid.Column="4" Content="{Binding Incident.IncidentID}"/>
<Label Grid.Row="1" Grid.Column="5" Content="{Binding Type.Name}"/>
<Label Grid.Row="1" Grid.Column="6" Content="{Binding Sensor.Name}"/>
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</ScrollViewer>
</Grid>
</StackPanel>
</TabItem>

I have the same markup and you should set MaxHeight property for ScrollViewer control. So this is my markup:
<Grid>
<ScrollViewer x:Name="ScrollViewer" ScrollChanged="ScrollViewer_ScrollChanged" MaxHeight="100">
<ListView ItemsSource="{Binding}">
<ListView.View>
<GridView>
<GridView.ColumnHeaderContainerStyle>
<Style TargetType="GridViewColumnHeader">
<Setter Property="Visibility" Value="Hidden" />
<Setter Property="Height" Value="0" />
</Style>
</GridView.ColumnHeaderContainerStyle>
<GridViewColumn Header="Log" DisplayMemberBinding="{Binding Text}">
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
</ScrollViewer>
</Grid>
And this is how it looks like:

The actual problem is, that the scrollviewer does not know how high it should render itself, so it will not show the scrollbar.
My approach is to set the height of the scrollviewer with a binding to a height that you know very well. So I have put your code into a test window and gave it a name
<Window x:Class="MyTest.MainWindow" x:Name="myWindow" >
...
<ScrollViewer Height="{Binding ElementName=myWindow, Path=Content.ActualHeight}" >
...
You can also use some other FrameworkElement of your choice to get the height from.

Related

How to use an if expression in Binding WPF - c#

Here is my code:
<ListView Grid.Row="1" x:Name="viewTicket" Style="{StaticResource ticketListBox}" ScrollViewer.HorizontalScrollBarVisibility="Disabled" Background="Transparent" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Center" BorderBrush="{x:Null}" SelectionChanged="ViewTicket_SelectionChanged">
<ListView.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid Grid.Row="0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="4*"/>
<ColumnDefinition Width="2*"/>
</Grid.ColumnDefinitions>
<Image Visibility="{Binding selectedCheck}" Name="check" Grid.Column="0" Margin="10,0,0,0" HorizontalAlignment="Left" VerticalAlignment="Center" Source="../../Images/check-donatota.png" Stretch="None" MouseLeftButtonUp="Check_MouseLeftButtonUp"/>
<TextBlock Visibility="{Binding selectedQuantity}" Name="quantity" Grid.Column="0" HorizontalAlignment="Center" VerticalAlignment="Center" TextWrapping="Wrap" Text="{Binding amount}"/>
<TextBlock Grid.Column="1" HorizontalAlignment="Left" VerticalAlignment="Center" Foreground="Black" TextWrapping="Wrap" Text="{Binding name}"/>
<TextBlock Visibility="{Binding selectedPrice}" Name="price" Grid.Column="2" HorizontalAlignment="Right" VerticalAlignment="Center" TextWrapping="Wrap" Text="{Binding total, StringFormat=C}"/>
<Image Visibility="{Binding selectedTrash}" Name="trash" Grid.Column="2" Margin="0,0,15,0" HorizontalAlignment="Right" VerticalAlignment="Center" Source="../../Images/trash-donatota.png" Stretch="None" MouseLeftButtonUp="Trash_MouseLeftButtonUp"/>
</Grid>
<ListView
ItemsSource="{Binding ingredients}"
Grid.Row="1"
Margin="-5,0,0,0"
Name="viewTicketIngs"
IsHitTestVisible="False"
Style="{StaticResource ticketListBox}"
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
ScrollViewer.VerticalScrollBarVisibility="Hidden"
Background="Transparent"
HorizontalContentAlignment="Stretch"
VerticalContentAlignment="Center"
BorderBrush="{x:Null}"
SelectionChanged="ViewTicketIngs_SelectionChanged">
<ListView.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="4*"/>
<ColumnDefinition Width="2*"/>
</Grid.ColumnDefinitions>
<TextBlock Visibility="Visible" Name="quantity" Grid.Column="0" Foreground="{DynamicResource GrayTextDonaTotaBrush}" HorizontalAlignment="Center" VerticalAlignment="Center" TextWrapping="Wrap" Text="{Binding amount}"/>
<TextBlock Margin="10,0,0,0" Grid.Column="1" Foreground="{DynamicResource GrayTextDonaTotaBrush}" HorizontalAlignment="Left" VerticalAlignment="Center" TextWrapping="Wrap" Text="{Binding ing.name}"/>
<TextBlock Visibility="Visible" Name="price" Grid.Column="2" Foreground="{DynamicResource GrayTextDonaTotaBrush}" HorizontalAlignment="Right" VerticalAlignment="Center" TextWrapping="Wrap" Text="{Binding total, StringFormat=C}"/>
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
I add data to the ListView viewTicket, but depending of a property I would like to change the ItemSource Binding of the ListView viewTicketIngs. In other words, is there anyway that I can use an if expression on the binding? Something like ItemsSource="{Binding IF(mode == 0) {ingredients} else {plates}}"
Change the Binding by a DataTrigger in a Style:
<ListView ...>
<ListView.Style>
<Style TargetType="ListView">
<Setter Property="ItemsSource" Value="{Binding plates}"/>
<Style.Triggers>
<DataTrigger Binding="{Binding mode}" Value="0">
<Setter Property="ItemsSource" Value="{Binding ingredients}"/>
</DataTrigger>
</Style.Triggers>
</Style>
</ListView.Style>
</ListView>
As I understand it, you sometimes dispaly plates, sometimes ingredients. Now there are triggers conditional display. WPF actually has a pretty wide support.
However what might be better is to have 2 different ViewModel classes and two (how I call them) "type targetting data tempaltes". Say you have these clases:
abstract class ViewModelItem { }
class Plate : ViewModelItem { }
class IngredientsList : ViewModelItem { }
The propety you exposie this in, would be set to ViewModelItem. In realtiy you would assign either a Plate or IngredientsList Instance.
Now you define two DataTemplates. A interesting thing about WPF is that if you do not specify a explicit Template, the Code will go out of it's way to try to find one. And it will do the matching via the DataType property of the Template (TargetType for Styles and similar). It works similar to what CSS does, with somebodies code going out of it's way to find a template to apply.

Controls vertical alignment with grid on the left and right

I have a custom listbox with a label and a checkbox in each row. I would like to have the label on the far left and the checkbox on the far right.
approach:
<ListBox x:Name="lbFieldsreq" HorizontalAlignment="Left" Height="100" Margin="513,232,0,0" VerticalAlignment="Top" Width="100">
<ListBox.ItemTemplate>
<DataTemplate>
<Grid ShowGridLines="True">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Label Content="{Binding name, Mode=OneWay}" Grid.Column="0" HorizontalAlignment="Left" />
<Label Grid.Column="1" HorizontalAlignment="Center" /> <!--Empty column -->
<CheckBox IsChecked="{Binding ticked ,Mode=OneWay}" Grid.Column="2" HorizontalAlignment="Right" />
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
current look:
Thx
Your XAML is mostly fine. All you really need to do is to set the ListBox.HorizontalContentAlignment property to "Stretch". This basically forces each item in the collection to stretch to fill with entire Width of the related ListBoxItem. However, you could improve this further by setting the Grid.IsSharedSizeScope Attached Property to True. Setting this in conjunction with the SharedSizeGroup property enables us to ensure that the column Widths of each column of the DataTemplate are the same. Try this:
<ListBox x:Name="lbFieldsreq" HorizontalAlignment="Left" Height="100" ItemsSource="{Binding Items}" VerticalAlignment="Top" HorizontalContentAlignment="Stretch">
<ListBox.ItemTemplate>
<DataTemplate>
<Grid ShowGridLines="True" Grid.IsSharedSizeScope="True">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" SharedSizeGroup="LabelColumn" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" SharedSizeGroup="CheckBoxColumn" />
</Grid.ColumnDefinitions>
<Label Content="{Binding}" Grid.Column="0" HorizontalAlignment="Left" />
<!--Empty column -->
<Label Grid.Column="1" HorizontalAlignment="Center" />
<CheckBox Grid.Column="2" IsChecked="{Binding ticked, Mode=OneWay}" HorizontalAlignment="Right" />
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>

Windows 8 XAML ListView Header not same size

Currently having an issue where the header of my ListView is larger than my ListView Items, so the header doesn't line up properly. I could use a margin on the header as a hack to fix it, but surely there's a proper way to fix this?
<DataTemplate x:Key="HeaderTemplate" >
<Grid Height="36" Background="#99999999" Margin="0,0,5,0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="3*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="3*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<TextBlock x:Uid="Name" TextWrapping="Wrap" HorizontalAlignment="Left" Text="Project" Grid.Column="0" Style="{StaticResource BodyTextBlockStyle}" />
<TextBlock x:Uid="Qty" TextWrapping="Wrap" HorizontalAlignment="Left" Text="Qty" Grid.Column="1" Style="{StaticResource BodyTextBlockStyle}" />
<TextBlock x:Uid="SubTotal" TextWrapping="Wrap" HorizontalAlignment="Left" Text="Sub Total" Grid.Column="2" Style="{StaticResource BodyTextBlockStyle}" />
<TextBlock x:Uid="Total" TextWrapping="Wrap" HorizontalAlignment="Left" Text="Total" Grid.Column="3" Style="{StaticResource BodyTextBlockStyle}" />
</Grid>
</DataTemplate>
// ...
<ListView x:Name="CartGridView" ItemsSource="{Binding CartItmes}" HeaderTemplate="{StaticResource HeaderTemplate}"
Grid.Row="1" VerticalAlignment="Stretch" Width="auto" ItemContainerStyle="{StaticResource SimpleListViewItemStyle}">
<ListView.ItemTemplate>
<DataTemplate>
<Grid Height="auto" Margin="0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="3*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="3*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0" Style="{StaticResource BodyTextBlockStyle}" HorizontalAlignment="Left"
Text="{Binding Name, Mode=TwoWay}"/>
<TextBlock Grid.Column="1" Style="{StaticResource BodyTextBlockStyle}" HorizontalAlignment="Center"
Text="{Binding Qty, Mode=TwoWay}"/>
<TextBlock Grid.Column="2" Style="{StaticResource BodyTextBlockStyle}" HorizontalAlignment="Left"
Text="{Binding SubTotal, Mode=TwoWay}"/>
<TextBlock Grid.Column="3" Style="{StaticResource BodyTextBlockStyle}" HorizontalAlignment="Center"
Text="{Binding Total, Mode=TwoWay}"/>
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
Add the following to your ListView definition
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
</Style>
</ListView.ItemContainerStyle>

Creating multiple tabitems from tabitem template in WPF C# XAML

I read many tutorials from MSDN about WPF styling and datatemplating and contenttemplating but no success.
I need to make same TabItems in my TabControl and I made manually TabItem which i want to use as host for Style and ContentTemplate for other TabItems in TabControl
<TabItem Header="1.semestar">
<Grid x:Name="GridSemestra">
<Grid.DataContext>
<ViewModel:PredmetVM/>
</Grid.DataContext>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition MinWidth="100"/>
<ColumnDefinition MinWidth="30"/>
</Grid.ColumnDefinitions>
<Grid.Children>
<ListBox x:Name="PredmetiLW" Grid.Row="0" BorderThickness="0" Grid.Column="0" ItemsSource="{Binding Predmeti}" HorizontalAlignment="Center" VerticalAlignment="Center" >
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Naziv}" />
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<ListBox x:Name="RadioLW" Grid.Row="0" Grid.Column="1" BorderThickness="0" ItemsSource="{Binding Predmeti}" HorizontalAlignment="Center" VerticalAlignment="Center" >
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Ocjena}"/>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<Label Content="Prosjek Semestra :" HorizontalAlignment="Right" VerticalAlignment="Center" Grid.Row="1" Grid.Column="0" />
<Label x:Name="_prosjekSemestra" Grid.Row="1" Grid.Column="1" ContentStringFormat="F2" Content="{Binding _prosjek, Mode=OneWay}" HorizontalAlignment="Center" VerticalAlignment="Center" />
<Label Content="Ostvareni ECTS-ovi :" HorizontalAlignment="right" VerticalAlignment="Center" Grid.Row="2" Grid.Column="0" />
<Label x:Name="_ectsSemestra" Grid.Row="2" Grid.Column="1" Content="{Binding _ectsovi, Mode=OneWay}" HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Grid.Children>
</Grid>
</TabItem>
This is how you define a style for any TabItem. In the example I created a white border and a black background for the Header content of the TabItem:
<Style TargetType="{x:Type TabItem}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type TabItem}">
<Border BorderBrush="White" BorderThickness="5" Margin="2">
<Grid Width="100" Height="100" Background="Black">
<ContentPresenter x:Name="ContentSite"
VerticalAlignment="Center"
HorizontalAlignment="Center"
ContentSource="Header"
RecognizesAccessKey="True"/>
</Grid>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
If you want your items to render with same template set the ItemTemplate for your TabControl like below:
<TabControl ItemsSource="{Binding MyTabItems}">
<TabControl.ItemTemplate>
<DataTemplate>
<Grid x:Name="GridSemestra">
<Grid.DataContext>
<ViewModel:PredmetVM/>
</Grid.DataContext>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition MinWidth="100"/>
<ColumnDefinition MinWidth="30"/>
</Grid.ColumnDefinitions>
<Grid.Children>
<ListBox x:Name="PredmetiLW" Grid.Row="0" BorderThickness="0" Grid.Column="0" ItemsSource="{Binding Predmeti}" HorizontalAlignment="Center" VerticalAlignment="Center" >
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Naziv}" />
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<ListBox x:Name="RadioLW" Grid.Row="0" Grid.Column="1" BorderThickness="0" ItemsSource="{Binding Predmeti}" HorizontalAlignment="Center" VerticalAlignment="Center" >
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Ocjena}"/>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<Label Content="Prosjek Semestra :" HorizontalAlignment="Right" VerticalAlignment="Center" Grid.Row="1" Grid.Column="0" />
<Label x:Name="_prosjekSemestra" Grid.Row="1" Grid.Column="1" ContentStringFormat="F2" Content="{Binding _prosjek, Mode=OneWay}" HorizontalAlignment="Center" VerticalAlignment="Center" />
<Label Content="Ostvareni ECTS-ovi :" HorizontalAlignment="right" VerticalAlignment="Center" Grid.Row="2" Grid.Column="0" />
<Label x:Name="_ectsSemestra" Grid.Row="2" Grid.Column="1" Content="{Binding _ectsovi, Mode=OneWay}" HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Grid.Children>
</Grid>
</DataTemplate>
</TabControl.ItemTemplate>
</TabControl>
Doing this, for all the items in property MyTabItems, TabItems will be generated

User Control Not Rendering When Used as a DataTemplate?

I have a usercontrol which I want to use as a DataTemplate in a Listbox.
This works:
<ListBox>
<ListBox.ItemTemplate>
<DataTemplate>
<Grid x:Name="Grid" Height="100" Width="880" Background="LightGray">
<Grid.RowDefinitions>
<RowDefinition Height="24"/>
<RowDefinition Height="24"/>
<RowDefinition Height="24"/>
<RowDefinition Height="24"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="190" />
<ColumnDefinition Width="100" />
<ColumnDefinition Width="100" />
<ColumnDefinition Width="100" />
<ColumnDefinition Width="190" />
<ColumnDefinition Width="200" />
</Grid.ColumnDefinitions>
<Label Grid.Column="0" Grid.Row="0">Client</Label>
<Label Grid.Column="0" Grid.Row="2">Contact</Label>
<Label Grid.Column="1" Grid.Row="0">Date Presentation</Label>
<Label Grid.Column="2" Grid.Row="0">Action</Label>
<Label Grid.Column="3" Grid.Row="0">Date Interview</Label>
<Label Grid.Column="3" Grid.Row="2">Time Interview</Label>
<Label Grid.Column="4" Grid.Row="0">Remarks</Label>
<Label Grid.Column="5" Margin="0,0,2,0">managed by</Label>
<ComboBox Grid.Column="0" Grid.Row="1" Margin="2" Text="{Binding Path=Customer}">
<!--Template-->
</ComboBox>
<TextBox Grid.Column="0" Grid.Row="3" Margin="2" Text="{Binding Path=Contact}"></TextBox>
<TextBox Grid.Column="1" Grid.Row="1" Margin="2" Text="{Binding Path=PresentationDate}"></TextBox>
<ComboBox Grid.Column="2" Grid.Row="1" Margin="2" Text="{Binding Path=Action}">
<!--Template-->
</ComboBox>
<TextBox Grid.Column="3" Grid.Row="1" Margin="2" Text="{Binding Path=InterviewDate}"></TextBox>
<TextBox Grid.Column="3" Grid.Row="3" Margin="2" Text="{Binding Path=InterviewTime}"></TextBox>
<TextBox Grid.Column="4" Grid.Row="1" Grid.RowSpan="3" Margin="2" Text="{Binding Path=Remarks}"></TextBox>
<StackPanel Orientation="Horizontal" Grid.Column="5" Grid.Row="1" >
<ComboBox Width="124" Text="{Binding Path=Manager}" Margin="2"></ComboBox>
<Button Width="60" Height="20" Margin="4,0,0,0" >Mail</Button>
</StackPanel>
<CheckBox Grid.Column="5" Grid.Row="3" Margin="2,2,4,2">Rejection communicated</CheckBox>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
If I put the exact same code from between the <DataTemplate> tags:
<UserControl x:Class="CandiMan.View.CandidatePresentationControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:cm="clr-namespace:CandiMan;assembly=CandiMan"
xmlns:vw="clr-namespace:CandiMan.View;assembly=CandiMan"
xmlns:vm="clr-namespace:CandiMan.ViewModel;assembly=CandiMan"
Height="100" Width="880" BorderBrush="Black" BorderThickness="1">
<Grid x:Name="Grid" Height="100" Width="880" Background="LightGray">
<Grid.RowDefinitions>
<RowDefinition Height="24"/>
<RowDefinition Height="24"/>
<RowDefinition Height="24"/>
<RowDefinition Height="24"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="190" />
<ColumnDefinition Width="100" />
<ColumnDefinition Width="100" />
<ColumnDefinition Width="100" />
<ColumnDefinition Width="190" />
<ColumnDefinition Width="200" />
</Grid.ColumnDefinitions>
<Label Grid.Column="0" Grid.Row="0">Client</Label>
<Label Grid.Column="0" Grid.Row="2">Contact</Label>
<Label Grid.Column="1" Grid.Row="0">Date Presentation</Label>
<Label Grid.Column="2" Grid.Row="0">Action</Label>
<Label Grid.Column="3" Grid.Row="0">Date Interview</Label>
<Label Grid.Column="3" Grid.Row="2">Time Interview</Label>
<Label Grid.Column="4" Grid.Row="0">Remarks</Label>
<Label Grid.Column="5" Margin="0,0,2,0">managed by</Label>
<ComboBox Grid.Column="0" Grid.Row="1" Margin="2" Text="{Binding Path=Customer}">
<!--Template-->
</ComboBox>
<TextBox Grid.Column="0" Grid.Row="3" Margin="2" Text="{Binding Path=Contact}"></TextBox>
<TextBox Grid.Column="1" Grid.Row="1" Margin="2" Text="{Binding Path=PresentationDate}"></TextBox>
<ComboBox Grid.Column="2" Grid.Row="1" Margin="2" Text="{Binding Path=Action}">
<!--Template-->
</ComboBox>
<TextBox Grid.Column="3" Grid.Row="1" Margin="2" Text="{Binding Path=InterviewDate}"></TextBox>
<TextBox Grid.Column="3" Grid.Row="3" Margin="2" Text="{Binding Path=InterviewTime}"></TextBox>
<TextBox Grid.Column="4" Grid.Row="1" Grid.RowSpan="3" Margin="2" Text="{Binding Path=Remarks}"></TextBox>
<StackPanel Orientation="Horizontal" Grid.Column="5" Grid.Row="1" >
<ComboBox Width="124" Text="{Binding Path=Manager}" Margin="2"></ComboBox>
<Button Width="60" Height="20" Margin="4,0,0,0" >Mail</Button>
</StackPanel>
<CheckBox Grid.Column="5" Grid.Row="3" Margin="2,2,4,2">Rejection communicated</CheckBox>
</Grid>
</UserControl>
into a usercontrol named CandidatePresentationControl and do it like
<ListBox>
<ListBox.ItemTemplate>
<DataTemplate>
<Grid>
<vw:CandidatePresentationControl/>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
it does not get rendered. No errors, just an empty listbox. Can someone help me??
Thank you!
edit: I forgot something, dunno if it matters: The whole thing I'm doing this in, is a usercontrol, too.
It shouldn't matter, that your referenced UserControl is within another UserControl. Try these steps to better debug your XAML-code: http://beacosta.com/blog/?p=52
Since you have your data hard wired in XAML, the only way to explain the empty ListBox is, that your UserControl can't be found by the parent UserControl, imo.
<ListBox>
<ListBox.ItemTemplate>
<DataTemplate>
<Grid>
<vw:CandidatePresentationControl DataContext="{Binding}"/>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
You have to write this way in order to bind datacontext, I would suggest you look at MVVM that will give you idea on how to do it even better way.

Categories

Resources