Combobox items not displaying from LINQ query - c#

I am trying to populate a combo-box with the contents from a table
(`InspectionTypes`) from a LINQ query without success for weeks.
When I insert a breakpoint, I can see that the data is there and the count
is correct, but nothing shows up in the drop-down list. I have a desktop
application with WPF and EF6. I am currently only working with
inspectionType10ComboBox but, there are nine other comboboxes that will
function exactly the same and use the exact same data. I am attempting to
build a quote based on which inspection(s) have been requested.
It looks like your post is mostly code; please add some more details.It looks like your post is mostly code; please add some more details.It looks like your post is mostly code; please add some more details.It looks like your post is mostly code; please add some more details.It looks like your post is mostly code; please add some more details.It looks like your post is mostly code; please add some more details.It looks like your post is mostly code; please add some more details.It looks like your post is mostly code; please add some more details.It looks like your post is mostly code; please add some more details.It looks like your post is mostly code; please add some more details.It looks like your post is mostly code; please add some more details.It looks like your post is mostly code; please add some more details.It looks like your post is mostly code; please add some more details.It looks like your post is mostly code; please add some more details.It looks like your post is mostly code; please add some more details.It looks like your post is mostly code; please add some more details.It looks like your post is mostly code; please add some more details.It looks like your post is mostly code; please add some more details.It looks like your post is mostly code; please add some more details.
**My code behind is as follows:**
using System;
using System.Collections.ObjectModel;
using System.Data;
using System.Data.Entity;
using System.Data.SQLite.Linq;
using System.Linq;
using System.Linq.Expressions;
using System.Data.SqlClient;
using System.Data.Common;
using System.Globalization;
using System.Text;
using System.Threading.Tasks;
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.Navigation;
namespace WpfApp1
{
/// <summary>
/// Interaction logic for EstimatesScreen.xaml
/// </summary>
public partial class EstimatesScreen : Window
{
MIDatabase01Entities1 context = new MIDatabase01Entities1();
CollectionViewSource estimatesViewSource;
public EstimatesScreen()
{
InitializeComponent();
estimatesViewSource = ((CollectionViewSource)
(FindResource("estimatesViewSource")));
DataContext = this;
FillComboBoxes();
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
System.Windows.Data.CollectionViewSource estimatesViewSource =
((System.Windows.Data.CollectionViewSource)
(this.FindResource("estimatesViewSource")));
context.Estimates.Load();
estimatesViewSource.Source = context.Estimates.Local;
}
private void FillComboBoxes()
{
var result = context.InspectionTypes.Select(p => new
{
ID = p.InspectionTypesID,
Name = p.InspectionTypeName
}).ToList();
inspectionType10ComboBox.ItemsSource = result;
inspectionType10ComboBox.SelectedValuePath = "ID";
inspectionType10ComboBox.DisplayMemberPath = "Name";
}
}
}
**My XAML is as follows (edited to reduce size. Removed "Newgrid which is
a duplacate if ExistingGrid with "New" prefix for all fields.):**
<Window x:Class="WpfApp1.EstimatesScreen"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfApp1"
mc:Ignorable="d"
Title="Monroe Inspections LLC" Height="600" Width="1000"
Loaded="Window_Loaded">
<Window.Resources>
<CollectionViewSource x:Key="estimatesViewSource" d:DesignSource="
{d:DesignInstance {x:Type local:Estimate}, CreateList=True}"/>
<CollectionViewSource x:Key="inspectionTypesViewSource"
d:DesignSource="{d:DesignInstance {x:Type local:InspectionType},
CreateList=True}"/>
<RoutedUICommand x:Key="FirstCommand" Text="First"/>
<RoutedUICommand x:Key="LastCommand" Text="Last"/>
<RoutedUICommand x:Key="NextCommand" Text="Next"/>
<RoutedUICommand x:Key="DeleteCommand" Text="Delete"/>
<RoutedUICommand x:Key="UpdateCommand" Text="Update"/>
<RoutedUICommand x:Key="AddCommand" Text="Add"/>
<RoutedUICommand x:Key="CancelCommand" Text="Cancel"/>
<RoutedUICommand x:Key="PreviousCommand" Text="Previous"/>
<Style x:Key="NavButton" TargetType="{x:Type Button}" BasedOn="
{x:Null}">
<Setter Property="FontSize" Value="24"/>
<Setter Property="FontFamily" Value="Segoe UI Symbol"/>
<Setter Property="Margin" Value="2,2,2,0"/>
<Setter Property="Width" Value="40"/>
<Setter Property="Height" Value="auto"/>
</Style>
</Window.Resources>
<Window.CommandBindings>
<CommandBinding Command="{StaticResource FirstCommand}"
Executed="FirstCommandHandler"/>
<CommandBinding Command="{StaticResource LastCommand}"
Executed="LastCommandHandler"/>
<CommandBinding Command="{StaticResource NextCommand}"
Executed="NextCommandHandler"/>
<CommandBinding Command="{StaticResource PreviousCommand}"
Executed="PreviousCommandHandler"/>
<CommandBinding Command="{StaticResource DeleteCommand}"
Executed="DeleteCommandHandler"/>
<CommandBinding Command="{StaticResource UpdateCommand}"
Executed="UpdateCommandHandler"/>
<CommandBinding Command="{StaticResource AddCommand}"
Executed="AddCommandHandler"/>
<CommandBinding Command="{StaticResource CancelCommand}"
Executed="CancelCommandHandler"/>
</Window.CommandBindings>
<Grid Margin="0,0,0,0">
<Label Content="QUOTES" HorizontalAlignment="Left"
VerticalAlignment="Top" Width="224" Height="51" FontWeight="Bold"
FontSize="36" Margin="173,9,0,0"/>
<Button Content="Return" HorizontalAlignment="Left" Margin="10,66,0,0"
VerticalAlignment="Top" Height="41" Width="136" Click="Return_Click"
FontWeight="Bold" FontFamily="Arial"/>
<Grid x:Name="ComboboxGrid" DataContext="{StaticResource
estimatesViewSource}" HorizontalAlignment="Left" Margin="165,62,0,0"
VerticalAlignment="Top">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Label Content="Existing Quote Customer:" Grid.Column="0"
HorizontalAlignment="Left" Margin="3" Grid.Row="0"
VerticalAlignment="Center"/>
<ComboBox x:Name="customerComboBox" Grid.Column="1"
DisplayMemberPath="Customer" HorizontalAlignment="Left" Height="Auto"
ItemsSource="{Binding}" Margin="3" Grid.Row="0" VerticalAlignment="Center"
Width="200">
<ComboBox.ItemsPanel>
<ItemsPanelTemplate>
<VirtualizingStackPanel/>
</ItemsPanelTemplate>
</ComboBox.ItemsPanel>
</ComboBox>
</Grid>
<Grid x:Name="ExistingGrid" DataContext="{StaticResource
estimatesViewSource}" HorizontalAlignment="Left" Margin="176,112,0,0"
VerticalAlignment="Top">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="115"/>
<ColumnDefinition Width="230"/>
<ColumnDefinition Width="210"/>
<ColumnDefinition Width="82"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="30"/>
<RowDefinition Height="30"/>
<RowDefinition Height="30"/>
<RowDefinition Height="30"/>
<RowDefinition Height="30"/>
<RowDefinition Height="30"/>
<RowDefinition Height="30"/>
<RowDefinition Height="30"/>
<RowDefinition Height="30"/>
<RowDefinition Height="30"/>
<RowDefinition Height="30"/>
<RowDefinition Height="30"/>
<RowDefinition Height="30"/>
</Grid.RowDefinitions>
<Label Content="Customer:" Grid.Column="0"
HorizontalAlignment="Left" Margin="3" Grid.Row="1"
VerticalAlignment="Center"/>
<TextBox x:Name="customerTextBox" Grid.Column="1"
HorizontalAlignment="Left" Height="24" Margin="3" Grid.Row="1" Text="
{Binding Customer, Mode=TwoWay, NotifyOnValidationError=true,
ValidatesOnExceptions=true}" VerticalAlignment="Center" Width="200"/>
<Label Content="Discount Price:" Grid.Column="2"
HorizontalAlignment="Right" Margin="3" Grid.Row="11"
VerticalAlignment="Center"/>
<TextBox x:Name="discountPriceTextBox" Grid.Column="3"
HorizontalAlignment="Left" Height="24" Margin="3" Grid.Row="11" Text="
{Binding DiscountPrice, Mode=TwoWay, NotifyOnValidationError=true,
ValidatesOnExceptions=true}" VerticalAlignment="Center" Width="70"/>
<Label Content="Expiration Date:" Grid.Column="0"
HorizontalAlignment="Left" Margin="3" Grid.Row="11"
VerticalAlignment="Center"/>
<DatePicker x:Name="estExpirationDateDatePicker" Grid.Column="1"
HorizontalAlignment="Left" Margin="3" Grid.Row="11" SelectedDate="{Binding
EstExpirationDate, Mode=TwoWay, NotifyOnValidationError=true,
ValidatesOnExceptions=true}" VerticalAlignment="Center" Width="125"/>
<Label Content="Quote Accepted:" Grid.Column="0"
HorizontalAlignment="Left" Margin="3" Grid.Row="12"
VerticalAlignment="Center"/>
<CheckBox x:Name="estimateAcceptedCheckBox" Content=""
Grid.Column="1" HorizontalAlignment="Left" IsChecked="{Binding
EstimateAccepted, Mode=TwoWay, NotifyOnValidationError=true,
ValidatesOnExceptions=true}" Margin="3" Grid.Row="12"
VerticalAlignment="Center"/>
<Label Content="Quote Date:" Grid.Column="0"
HorizontalAlignment="Left" Margin="3" Grid.Row="10"
VerticalAlignment="Center"/>
<DatePicker x:Name="estimateDateDatePicker" Grid.Column="1"
HorizontalAlignment="Left" Margin="3" Grid.Row="10" SelectedDate="{Binding
EstimateDate, Mode=TwoWay, NotifyOnValidationError=true,
ValidatesOnExceptions=true}" VerticalAlignment="Center" Width="125"/>
<Label Content="Estimated Price Total:" Grid.Column="2"
HorizontalAlignment="Right" Margin="3" Grid.Row="12"
VerticalAlignment="Center"/>
<TextBox x:Name="estimatedPriceTotalTextBox" Grid.Column="3"
HorizontalAlignment="Left" Height="24" Margin="3" Grid.Row="12" Text="
{Binding EstimatedPriceTotal, Mode=TwoWay, NotifyOnValidationError=true,
ValidatesOnExceptions=true}" VerticalAlignment="Center" Width="70"/>
<Label Content="Quote ID:" Grid.Column="0"
HorizontalAlignment="Left" Margin="3" Grid.Row="0"
VerticalAlignment="Center"/>
<TextBox x:Name="estimatesIDTextBox" Grid.Column="1"
HorizontalAlignment="Left" Height="24" Margin="3" Grid.Row="0" Text="
{Binding EstimatesID, Mode=TwoWay, NotifyOnValidationError=true,
ValidatesOnExceptions=true}" VerticalAlignment="Center" Width="70"/>
<Label Content="Square Footage:" Grid.Column="0"
HorizontalAlignment="Left" Margin="3" Grid.Row="5"
VerticalAlignment="Center"/>
<TextBox x:Name="squareFootageTextBox" Grid.Column="1"
HorizontalAlignment="Left" Height="24" Margin="3" Grid.Row="5" Text="
{Binding SquareFootage, Mode=TwoWay, NotifyOnValidationError=true,
ValidatesOnExceptions=true}" VerticalAlignment="Center" Width="70"/>
<TextBox x:Name="inspectionCost1TextBox" Grid.Column="3"
HorizontalAlignment="Left" Height="24" Margin="3" Grid.Row="1" Text="
{Binding InspectionCost1, Mode=TwoWay, NotifyOnValidationError=true,
ValidatesOnExceptions=true}" VerticalAlignment="Center" Width="70"/>
<TextBox x:Name="inspectionCost10TextBox" Grid.Column="3"
HorizontalAlignment="Left" Height="23" Margin="3" Grid.Row="10" Text="
{Binding InspectionCost10, Mode=TwoWay, NotifyOnValidationError=true,
ValidatesOnExceptions=true}" VerticalAlignment="Center" Width="70"/>
<TextBox x:Name="inspectionCost2TextBox" Grid.Column="3"
HorizontalAlignment="Left" Height="24" Margin="3" Grid.Row="2" Text="
{Binding InspectionCost2, Mode=TwoWay, NotifyOnValidationError=true,
ValidatesOnExceptions=true}" VerticalAlignment="Center" Width="70"/>
<TextBox x:Name="inspectionCost3TextBox" Grid.Column="3"
HorizontalAlignment="Left" Height="24" Margin="3" Grid.Row="3" Text="
{Binding InspectionCost3, Mode=TwoWay, NotifyOnValidationError=true,
ValidatesOnExceptions=true}" VerticalAlignment="Center" Width="70"/>
<TextBox x:Name="inspectionCost4TextBox" Grid.Column="3"
HorizontalAlignment="Left" Height="23" Margin="3" Grid.Row="4" Text="
{Binding InspectionCost4, Mode=TwoWay, NotifyOnValidationError=true,
ValidatesOnExceptions=true}" VerticalAlignment="Center" Width="70"/>
<TextBox x:Name="inspectionCost5TextBox" Grid.Column="3"
HorizontalAlignment="Left" Height="22" Margin="3" Grid.Row="5" Text="
{Binding InspectionCost5, Mode=TwoWay, NotifyOnValidationError=true,
ValidatesOnExceptions=true}" VerticalAlignment="Center" Width="70"/>
<TextBox x:Name="inspectionCost6TextBox" Grid.Column="3"
HorizontalAlignment="Left" Height="22" Margin="3" Grid.Row="6" Text="
{Binding InspectionCost6, Mode=TwoWay, NotifyOnValidationError=true,
ValidatesOnExceptions=true}" VerticalAlignment="Center" Width="70"/>
<TextBox x:Name="inspectionCost7TextBox" Grid.Column="3"
HorizontalAlignment="Left" Height="22" Margin="3" Grid.Row="7" Text="
{Binding InspectionCost7, Mode=TwoWay, NotifyOnValidationError=true,
ValidatesOnExceptions=true}" VerticalAlignment="Center" Width="70"/>
<TextBox x:Name="inspectionCost8TextBox" Grid.Column="3"
HorizontalAlignment="Left" Height="23" Margin="3" Grid.Row="8" Text="
{Binding InspectionCost8, Mode=TwoWay, NotifyOnValidationError=true,
ValidatesOnExceptions=true}" VerticalAlignment="Center" Width="70"/>
<TextBox x:Name="inspectionCost9TextBox" Grid.Column="3"
HorizontalAlignment="Left" Height="23" Margin="3" Grid.Row="9" Text="
{Binding InspectionCost9, Mode=TwoWay, NotifyOnValidationError=true,
ValidatesOnExceptions=true}" VerticalAlignment="Center" Width="70"/>
<ComboBox x:Name="inspectionType1ComboBox"
Grid.Column="2" Grid.Row="1"
Height="24" Width="200" Margin="3"
HorizontalAlignment="Left" VerticalAlignment="Center"
DataContext="inspectionTypesViewSource"
SelectedValuePath="InspectionTypeName"
SelectedValue="InspectionTypeName"
DisplayMemberPath="InspectionTypeName"
ItemsSource="{Binding result}" >
<ComboBox.ItemsPanel>
<ItemsPanelTemplate>
<VirtualizingStackPanel/>
</ItemsPanelTemplate>
</ComboBox.ItemsPanel>
</ComboBox>
This is the ComboBox I am currently working on. There are nine others that will have to work exactly the same, with the dame data.
<ComboBox x:Name="inspectionType10ComboBox"
Grid.Column="2" Grid.Row="10"
Height="24" Width="200" Margin="3"
HorizontalAlignment="Left" VerticalAlignment="Center">
<ComboBox.ItemsPanel>
<ItemsPanelTemplate>
<VirtualizingStackPanel/>
</ItemsPanelTemplate>
</ComboBox.ItemsPanel>
</ComboBox>
<ComboBox x:Name="inspectionType2ComboBox" Grid.Column="2"
DisplayMemberPath="InspectionType2" HorizontalAlignment="Left"
Height="Auto" ItemsSource="{Binding}" Margin="3" Grid.Row="2"
VerticalAlignment="Center" Width="200">
<ComboBox.ItemsPanel>
<ItemsPanelTemplate>
<VirtualizingStackPanel/>
</ItemsPanelTemplate>
</ComboBox.ItemsPanel>
</ComboBox>
<ComboBox x:Name="inspectionType3ComboBox" Grid.Column="2"
DisplayMemberPath="InspectionType3" HorizontalAlignment="Left"
Height="Auto" ItemsSource="{Binding}" Margin="3" Grid.Row="3"
VerticalAlignment="Center" Width="200">
<ComboBox.ItemsPanel>
<ItemsPanelTemplate>
<VirtualizingStackPanel/>
</ItemsPanelTemplate>
</ComboBox.ItemsPanel>
</ComboBox>
<ComboBox x:Name="inspectionType4ComboBox" Grid.Column="2"
DisplayMemberPath="InspectionType4" HorizontalAlignment="Left"
Height="Auto" ItemsSource="{Binding}" Margin="3" Grid.Row="4"
VerticalAlignment="Center" Width="200">
<ComboBox.ItemsPanel>
<ItemsPanelTemplate>
<VirtualizingStackPanel/>
</ItemsPanelTemplate>
</ComboBox.ItemsPanel>
</ComboBox>
<ComboBox x:Name="inspectionType5ComboBox" Grid.Column="2"
DisplayMemberPath="InspectionType5" HorizontalAlignment="Left"
Height="Auto" ItemsSource="{Binding}" Margin="3" Grid.Row="5"
VerticalAlignment="Center" Width="200">
<ComboBox.ItemsPanel>
<ItemsPanelTemplate>
<VirtualizingStackPanel/>
</ItemsPanelTemplate>
</ComboBox.ItemsPanel>
</ComboBox>
<ComboBox x:Name="inspectionType6ComboBox" Grid.Column="2"
DisplayMemberPath="InspectionType6" HorizontalAlignment="Left"
Height="Auto" ItemsSource="{Binding}" Margin="3" Grid.Row="6"
VerticalAlignment="Center" Width="200">
<ComboBox.ItemsPanel>
<ItemsPanelTemplate>
<VirtualizingStackPanel/>
</ItemsPanelTemplate>
</ComboBox.ItemsPanel>
</ComboBox>
<ComboBox x:Name="inspectionType7ComboBox" Grid.Column="2"
DisplayMemberPath="InspectionType7" HorizontalAlignment="Left"
Height="Auto" ItemsSource="{Binding}" Margin="3" Grid.Row="7"
VerticalAlignment="Center" Width="200">
<ComboBox.ItemsPanel>
<ItemsPanelTemplate>
<VirtualizingStackPanel/>
</ItemsPanelTemplate>
</ComboBox.ItemsPanel>
</ComboBox>
<ComboBox x:Name="inspectionType8ComboBox" Grid.Column="2"
DisplayMemberPath="InspectionType8" HorizontalAlignment="Left"
Height="Auto" ItemsSource="{Binding}" Margin="3" Grid.Row="8"
VerticalAlignment="Center" Width="200">
<ComboBox.ItemsPanel>
<ItemsPanelTemplate>
<VirtualizingStackPanel/>
</ItemsPanelTemplate>
</ComboBox.ItemsPanel>
</ComboBox>
<ComboBox x:Name="inspectionType9ComboBox" Grid.Column="2"
DisplayMemberPath="InspectionType9" HorizontalAlignment="Left"
Height="Auto" ItemsSource="{Binding}" Margin="3" Grid.Row="9"
VerticalAlignment="Center" Width="200">
<ComboBox.ItemsPanel>
<ItemsPanelTemplate>
<VirtualizingStackPanel/>
</ItemsPanelTemplate>
</ComboBox.ItemsPanel>
</ComboBox>
<Label Content="Address:" Grid.Column="0"
HorizontalAlignment="Left" Margin="3" Grid.Row="4"
VerticalAlignment="Center"/>
<TextBox x:Name="addressTextBox" Grid.Column="1"
HorizontalAlignment="Left" Height="24" Margin="3" Grid.Row="4" Text="
{Binding Address, Mode=TwoWay, NotifyOnValidationError=true,
ValidatesOnExceptions=true}" VerticalAlignment="Center" Width="200"/>
<Label Content="Inspection Type" Grid.Column="2"
HorizontalAlignment="Left" Margin="3" VerticalAlignment="Top" Width="97"/>
<Label Content="Cost" Grid.Column="3" HorizontalAlignment="Left"
Margin="3" VerticalAlignment="Top" Width="47"/>
<Label Content="Email:" Grid.Column="0" HorizontalAlignment="Left"
Margin="3" Grid.Row="2" VerticalAlignment="Center"/>
<TextBox x:Name="customerEmailTextBox" HorizontalAlignment="Left"
Height="23" Margin="3" Grid.Row="2" Text="{Binding CustomerEmail,
Mode=TwoWay, NotifyOnValidationError=true, ValidatesOnExceptions=true}"
VerticalAlignment="Center" Width="215" Grid.Column="1"/>
<Label Content="Crawl Space:" Grid.Column="0"
HorizontalAlignment="Left" Margin="3" Grid.Row="6"
VerticalAlignment="Center"/>
<CheckBox x:Name="crawalSpaceCheckBox1" Content=""
HorizontalAlignment="Left" IsChecked="{Binding CrawalSpace, Mode=TwoWay,
NotifyOnValidationError=true, ValidatesOnExceptions=true}" Margin="3"
Grid.Row="6" VerticalAlignment="Center" Grid.Column="1"/>
<TextBox x:Name="additionalDiscountTextBox" Grid.Column="1"
HorizontalAlignment="Left" Height="23" Margin="3" Grid.Row="8" Text="
{Binding AdditionalDiscount, Mode=TwoWay, NotifyOnValidationError=true,
ValidatesOnExceptions=true}" VerticalAlignment="Center" Width="70"/>
<Label Content="Extra Discount:" Grid.Column="0"
HorizontalAlignment="Left" Margin="3" Grid.Row="8"
VerticalAlignment="Center"/>
</Grid>
`NewGrid (removed for length constraints) goes here.`
<StackPanel Orientation="Horizontal" Height="35"
VerticalAlignment="Bottom" Background="Gainsboro" DataContext="
{StaticResource estimatesViewSource}" Margin="0,0,0,0">
<Button Name="btnFirst" Content="|◄" Command="{StaticResource
FirstCommand}" Style="{StaticResource NavButton}"/>
<Button Name="btnPrev" Content="◄" Command="{StaticResource
PreviousCommand}" Style="{StaticResource NavButton}"/>
<Button Name="btnNext" Content="►" Command="{StaticResource
NextCommand}" Style="{StaticResource NavButton}"/>
<Button Name="btnLast" Content="►|" Command="{StaticResource
LastCommand}" Style="{StaticResource NavButton}"/>
<Button Name="btnDelete" Content="Delete" Command="{StaticResource
DeleteCommand}" FontSize="11" Width="80" Style="{StaticResource
NavButton}"/>
<Button Name="btnAdd" Content="Add New" Command="{StaticResource
AddCommand}" FontSize="11" Width="80" Style="{StaticResource NavButton}"/>
<Button Name="btnUpdate" Content="Save" Command="{StaticResource
UpdateCommand}" FontSize="11" Width="80" Style="{StaticResource
NavButton}"/>
<Button Name="btnCancel" Content="Cancel" Command="{StaticResource
CancelCommand}" FontSize="11" Width="80" Style="{StaticResource
NavButton}"/>
</StackPanel>
</Grid>
</Window>`
`I have been looking at hundreds of samples and I am lost. The data for
the ComboBox is in my InspectionTypes table.
`

Related

Grid with header row and usercontrol for rows (columns)

I have the following control, the first row is a header row. There will always be at least one additional row. (minimum of 2 total rows).
I've thought about making the content row into a UserControl but unsure about how to set the content of the UserControl into the two columns. (Stack in Column 0 and TriggerForWord in Column 1)
What is the best way to implement adding rows dynamically and setting the content? UserControl loaded into each row? Something else?
<Grid Grid.Row="3" Margin="10,10,10,0">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<TextBlock Grid.Row="0" Grid.Column="0" Text="{Binding Source={x:Static localization:Resources.WordToTriggerAction}}" Margin="2 8 2 8" FontWeight="SemiBold" />
<TextBlock Grid.Row="0" Grid.Column="1" Text="{Binding Source={x:Static localization:Resources.Trigger}}" Margin="12 8 2 8" FontWeight="SemiBold" />
<!-- dynamic part -->
<StackPanel x:Name="Stack" Orientation="Horizontal" Grid.Row="1" Grid.Column="0" Margin="0,0,10,20" VerticalAlignment="Top">
<telerik:RadAutoCompleteBox x:Name="WordForAction" Width="300" WatermarkContent="{Binding Source={x:Static localization:Resources.EnterWordForAction}}" Margin="0" ItemsSource="{Binding Path=Words}"
DisplayMemberPath="word" SelectionMode="Single" AutoCompleteMode="Append" SearchTextChanged="WordForAction_SearchTextChanged" />
<Button IsEnabled="{Binding Path=SearchText.Length, ElementName=WordForAction}" IsTabStop="False" Height="{Binding Path=ActualHeight, ElementName=WordForAction}" FontFamily="{StaticResource TelerikWebUI}" FontSize="15" Content="{StaticResource GlyphPlus}" ToolTip="{Binding Source={x:Static localization:Resources.AddWord}}" VerticalAlignment="Bottom" />
<Button IsEnabled="{Binding Path=SearchText.Length, ElementName=WordForAction}" IsTabStop="False" Height="{Binding Path=ActualHeight, ElementName=WordForAction}" FontFamily="{StaticResource TelerikWebUI}" FontSize="15" Content="{StaticResource GlyphMinus}" ToolTip="{Binding Source={x:Static localization:Resources.RemoveWord}}" VerticalAlignment="Bottom" />
</StackPanel>
<telerik:RadComboBox x:Name="TriggerForWord" Grid.Row="1" Grid.Column="1" Width="150" EmptyText="{Binding Source={x:Static localization:Resources.Trigger}}" IsEditable="False" IsEnabled="False" SelectedValuePath="uuid" SelectionChanged="TriggerForWord_SelectionChanged"
Height="{Binding ElementName=WordForAction, Path=ActualHeight}" Margin="10 0 0 0" ItemsSource="{Binding Path=Triggers}" DisplayMemberPath="description" VerticalAlignment="Top" />
</Grid>
For other folks who come this way ...
<Grid Grid.Row="3" Margin="0,10,0,0" >
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="310"/>
<ColumnDefinition Width="150"/>
</Grid.ColumnDefinitions>
<TextBlock Grid.Row="0" Grid.Column="0" Text="{Binding Source={x:Static localization:Resources.WordToTriggerAction}}" Margin="2 8 2 8" FontWeight="SemiBold" />
<TextBlock Grid.Row="0" Grid.Column="1" Text="{Binding Source={x:Static localization:Resources.Trigger}}" Margin="2 8 2 8" FontWeight="SemiBold" />
<ItemsControl Grid.Row="1" Grid.ColumnSpan="2" ItemsSource="{Binding Path=WordsForAction}" x:Name="WordsForActionItems" >
<ItemsControl.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Left" Margin="0, 0, 0, 5">
<StackPanel Orientation="Horizontal" Margin="0" VerticalAlignment="Top" Width="310">
<telerik:RadAutoCompleteBox x:Name="WordForAction" Width="250" WatermarkContent="{Binding Source={x:Static localization:Resources.EnterWordForAction}}" Margin="0"
ItemsSource="{Binding Path=Words, ElementName=_this}" DisplayMemberPath="Word" SearchText="{Binding Word}"
SelectionMode="Single" AutoCompleteMode="Append" SearchTextChanged="WordForAction_SearchTextChanged" />
<Button Name="AddWord" IsEnabled="True" IsTabStop="False" Height="{Binding Path=ActualHeight, ElementName=WordForAction}" FontFamily="{StaticResource TelerikWebUI}" FontSize="15" Content="{StaticResource GlyphPlus}" Click="AddWord_Click" ToolTip="{Binding Source={x:Static localization:Resources.AddWord}}" VerticalAlignment="Bottom" />
<Button Name="RemoveWord" IsEnabled="{Binding Items.Count, ElementName=WordsForActionItems, Converter={StaticResource CountToBoolConverter}}" IsTabStop="False" Height="{Binding Path=ActualHeight, ElementName=WordForAction}" FontFamily="{StaticResource TelerikWebUI}" FontSize="15" Content="{StaticResource GlyphMinus}" Click="RemoveWord_Click" ToolTip="{Binding Source={x:Static localization:Resources.RemoveWord}}" VerticalAlignment="Bottom" />
</StackPanel>
<telerik:RadComboBox Grid.Column="1" x:Name="TriggerForWord" Width="150" EmptyText="Trigger" IsEditable="False" IsEnabled="True" SelectionChanged="TriggerForWord_SelectionChanged"
Margin="0" ItemsSource="{Binding Path=Triggers, ElementName=_this}" SelectedValuePath="uuid" DisplayMemberPath="description" SelectedValue="{Binding Trigger_uuid}" />
</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</Grid>

WPF Inner Collection virtualization not working

I have implemented below mentioned code in WPF in that I have implemented virtualization of lazy loading but it's not work when my inner collection have a 1000 of record then it will take much time to load on screen.
<ListBox x:Name="Mappingcontrol" Grid.Row="1"
DataContext="{Binding ElementName=Grids,Path=DataContext}"
VerticalAlignment="Stretch" HorizontalAlignment="Stretch"
ItemsSource="{Binding Path=MultiMappingCollectionList, Mode=TwoWay}"
VirtualizingStackPanel.IsVirtualizing="True"
VirtualizingStackPanel.VirtualizationMode="Recycling"
BorderThickness="0" BorderBrush="Transparent"
Background="Transparent"
HorizontalContentAlignment="Stretch"
VerticalContentAlignment="Stretch"
ItemContainerStyle="{StaticResource TransparentListBoxStyle}">
<ListBox.ItemTemplate>
<DataTemplate>
<Border Padding="0,10,0,10" BorderThickness="0,0,0,1"
BorderBrush="{StaticResource Gray5SolidBrush}">
<Grid x:Name="Gridmain" Margin="4,0,0,0">
<Grid.ColumnDefinitions>
<ColumnDefinition x:Name="default" Width="0.5*" SharedSizeGroup="default" />
<ColumnDefinition x:Name="atrioValue" Width="1*"
SharedSizeGroup="atrioValue" />
<ColumnDefinition x:Name="externalValue" Width="2*"
SharedSizeGroup="externalValue" />
</Grid.ColumnDefinitions>
<ToggleButton VerticalAlignment="Top"
HorizontalAlignment="Left"
Style="{DynamicResource ToggleButtonStyle}"
Margin="30,12,10,10" IsTabStop="False" Width="25"
Height="25"
IsChecked="{Binding IsDefault, Mode=TwoWay}">
<TextBlock Grid.Column="1" Margin="0,15,10,10" HorizontalAlignment="Left"
VerticalAlignment="Top"
Text="{Binding Path=Description}"
Style="{StaticResource ContentDataText}"
Name="txtDescription" />
<ListBox x:Name="GroupListBox" Grid.Column="2"
ItemsSource="{Binding Path=MultiMapping,Mode=TwoWay}"
HorizontalContentAlignment="Stretch"
BorderThickness="0"
BorderBrush="Transparent"
Background="Transparent"
VerticalContentAlignment="Stretch"
VirtualizingStackPanel.IsVirtualizing="True"
VirtualizingStackPanel.VirtualizationMode="Recycling"
VirtualizingStackPanel.CacheLength="2,3"
VirtualizingStackPanel.CacheLengthUnit="Page"
ItemContainerStyle="{StaticResource TransparentListBoxStyle}">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" CanVerticallyScroll="True" Height="200">
<telerik:RadWatermarkTextBox x:Name="ExternalValueTextBox"
HorizontalAlignment="Left"
TabIndex="100"
KeyboardNavigation.TabIndex="100"
IsTabStop="True"
Width="250"
MaxLength="35"
TextWrapping="Wrap"
Validation.ErrorTemplate="{DynamicResource CustomErrorTemplate}"
Text="{Binding Path=ExternalValue, Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"
PreviewTextInput="ExternalValueTextBox_OnPreviewTextInput"
Style="{DynamicResource RadWatermarkTextBoxDefault}"
Visibility="{Binding Path=ExternalValue,Converter={StaticResource StarVisibilityConverter}}"
Margin="0,5,0,0">
</telerik:RadWatermarkTextBox>
<Button x:Name="DeleteButton" Background="Transparent"
BorderThickness="0"
BorderBrush="Transparent"
CommandParameter="{Binding}"
Command="{Binding DataContext.RemoveGrouplistCommand, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}}"
HorizontalAlignment="Right"
VerticalAlignment="Center"
Visibility="{Binding Path=RemoveButtonVisibility,Converter={StaticResource BooleanHiddenVisibleConverter},Mode=TwoWay}"
Margin="15,5,15,0"
Style="{DynamicResource ButtonInvisibleNoColorEffects}">
<Button.Content>
<Rectangle Style="{StaticResource SmallCloseIcon}" />
</Button.Content>
</Button>
<Grid x:Name="AddGrid"
Visibility="{Binding Path=AddbuttonVisibility,Converter={StaticResource BooleanVisibilityConverter}}">
<controls:ActionImageButton x:Name="AddButton"
Content="Add Another"
DataContext="{Binding ElementName=Root,Path=DataContext}"
CommandParameter="{Binding ElementName=txtDescription,Path=Text}"
Command="{Binding AddGrouplistCommand}"
HorizontalAlignment="Right"
VerticalAlignment="Center"
IsEnabled="{Binding ElementName=ExternalValueTextBox,Path=Text,Converter={StaticResource StarVisibilityConverter},ConverterParameter=CanAdd}"
Margin="5,5,30,5"
Style="{StaticResource ActionImageButtonMedium}" />
</Grid>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Grid>
</Border>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
It would be great help if anyone can light on me what's I am doing wrong in it
Thanks in advance.

The name 'xxx' does not exist in the current context in WP7

this is my xaml code:
<TextBox x:Name="name_box_det" Text="{Binding Name}" Height="65" Margin="-12,-10,0,0" Grid.Row="1" TextWrapping="Wrap" VerticalAlignment="Top" Foreground="#FF40AA2F" HorizontalAlignment="Left" Width="467" SelectionBackground="#FF40AA2F" SelectionForeground="White" BorderBrush="#FF3FA92E" FontSize="18.667"/>
And this is C# code, to get text value:
var name_text_det = name_box_det.Text;
And I'm getting this exception:
The name 'name_box_det' does not exist in the current context
Xaml code is copied from another xaml, but I tried to write completely new and it does not help. Do you know where is error?
This is complete XAML code:
<Grid x:Name="LayoutRoot" Background="Transparent">
<Image Margin="0" Grid.Row="1" Source="devdesk.png" Stretch="Fill"/>
<StackPanel x:Name="ContentPanel" Grid.Row="1" Margin="12,45,12,12"Orientation="Horizontal">
<ListBox x:Name="listBox1">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel>
<TextBlock Height="27" Margin="0,0,0,0" Grid.Row="1" TextWrapping="Wrap" Text="Record index:" VerticalAlignment="Top" Foreground="#FF6C6C6C"/>
<TextBox Text="{Binding Index}" x:Name="index_box_det" Height="65" Margin="-12,-10,0,0" Grid.Row="1" TextWrapping="Wrap" VerticalAlignment="Top" Foreground="#FF40AA2F" HorizontalAlignment="Left" Width="467" SelectionBackground="#FF40AA2F" SelectionForeground="White" BorderBrush="#FF3FA92E" FontSize="18.667"/>
<TextBlock Name="record_name" Height="27" Margin="0,-10,0,0" Grid.Row="1" TextWrapping="Wrap" Text="Record name:" VerticalAlignment="Top" Foreground="#FF6C6C6C"/>
<TextBox x:Name="name_box_det" Text="{Binding Name}" Height="65" Margin="-12,-10,0,0" Grid.Row="1" TextWrapping="Wrap" VerticalAlignment="Top" Foreground="#FF40AA2F" HorizontalAlignment="Left" Width="467" SelectionBackground="#FF40AA2F" SelectionForeground="White" BorderBrush="#FF3FA92E" FontSize="18.667"/>
<TextBlock Height="27" Margin="0,-10,0,0" Grid.Row="1" TextWrapping="Wrap" Text="Beneficiary:" VerticalAlignment="Top" Foreground="#FF6C6C6C"/>
<TextBox x:Name="beneficiary_box_det" Text="{Binding Beneficiary}" Height="65" Margin="-12,-10,0,0" Grid.Row="1" TextWrapping="Wrap" VerticalAlignment="Top" Foreground="#FF40AA2F" HorizontalAlignment="Left" Width="467" SelectionBackground="#FF40AA2F" SelectionForeground="White" BorderBrush="#FF3FA92E" FontSize="18.667"/>
<TextBlock Height="27" Margin="0,-10,0,0" Grid.Row="1" TextWrapping="Wrap" Text="Price:" VerticalAlignment="Top" Foreground="#FF6C6C6C"/>
<TextBox x:Name="price_box_det" Height="65" Text="{Binding Price}" Margin="-12,-10,0,0" Grid.Row="1" TextWrapping="Wrap" VerticalAlignment="Top" Foreground="#FF40AA2F" HorizontalAlignment="Left" Width="467" SelectionBackground="#FF40AA2F" SelectionForeground="White" BorderBrush="#FF3FA92E" FontSize="18.667"/>
<TextBlock Margin="0,-10,0,0" Grid.Row="1" TextWrapping="Wrap" Text="Deadline:" Foreground="#FF6C6C6C"/>
<TextBox x:Name="deadline_box_det" Text="{Binding Deadline}" Margin="-12,-10,0,0" Grid.Row="1" TextWrapping="Wrap" Foreground="#FF40AA2F" HorizontalAlignment="Left" Width="467" SelectionBackground="#FF40AA2F" SelectionForeground="White" BorderBrush="#FF3FA92E" FontSize="18.667"/>
<TextBlock Margin="0,-10,0,0" Grid.Row="1" TextWrapping="Wrap" Text="Description:" Foreground="#FF6C6C6C" Height="27" VerticalAlignment="Bottom"/>
<TextBox x:Name="description_box_det" Text="{Binding Description}" Margin="-12,-10,0,0" Grid.Row="1" TextWrapping="Wrap" Foreground="#FF40AA2F" HorizontalAlignment="Left" Width="467" SelectionBackground="#FF40AA2F" SelectionForeground="White" BorderBrush="#FF3FA92E" FontSize="18.667" Height="285" VerticalAlignment="Bottom"/>
<Button Width="375" x:Name="edtbtn" Content="Edit this record" Click="edtbtn_Click" Height="88" Margin="-12,-10,0,0" Grid.Row="1" VerticalAlignment="Bottom" HorizontalAlignment="Left" BorderThickness="3" Foreground="#FF40AA2F" BorderBrush="#FF40AA2F" Background="{x:Null}"/>
<Button Width="100" x:Name="dltbtn" Click="dltbtn_Click" Height="88" Margin="-12,-98,0,0" Grid.Row="1" HorizontalAlignment="Right" VerticalAlignment="Bottom" BorderThickness="3" Foreground="#FF40AA2F" BorderBrush="#FF40AA2F" Background="{x:Null}">
<StackPanel>
<Image Source="delete.png"/>
</StackPanel>
</Button>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</StackPanel>
</Grid>
name_box_det exists within the ItemTemplate of your ListBox. This is a different context to your page and hence the error. Because an instance of this TextBlock will exist for every item in the collection your there's no way to know which one you're referring to in the code behind.
I'm guessing you're doing this in the Delete button click event handler. As you haven't provided a full repro of what you're doing here's an example of how it may be done.
Assuming the UI contains:
<ListBox ItemsSource="{Binding}">
<ListBox.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<TextBlock Text="{Binding Name}" />
<Button Content="delete" Grid.Column="1" Click="DeleteClicked"/>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
and the DataContext is something like:
this.DataContext = new[]
{
new SimpleViewModel { Name = "one" },
new SimpleViewModel { Name = "two" },
new SimpleViewModel { Name = "three" },
};
Then the click event handler can look like this:
private void DeleteClicked(object sender, RoutedEventArgs e)
{
MessageBox.Show(
"You're trying to delete " +
((sender as FrameworkElement).DataContext as SimpleViewModel).Name);
}

validating model in silverlight MVVM

how to validate in model in silverlight?
The code sample what Im trying to achieve is shown below..
<Grid x:Name="AddnewGrid" Margin="2" DataContext="{Binding SaveUpdateEmp, Mode=TwoWay">
<Grid.RowDefinitions>
<RowDefinition Height="*"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="125"></ColumnDefinition>
<ColumnDefinition Width="10"></ColumnDefinition>
<ColumnDefinition Width="*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<TextBlock x:Name="EmployeeCode" Text="EmployeeCode" FontSize="14" Grid.Row="0" Grid.Column="0" VerticalAlignment="Center"></TextBlock>
<TextBlock x:Name="EmployeeCodeSprtr" Text=":" FontSize="14" Grid.Row="0" Grid.Column="1" VerticalAlignment="Center"></TextBlock>
<TextBox x:Name="txtEmployeeCode" Text="{Binding EmployeeCode, Mode=TwoWay, ValidatesOnDataErrors=True}" Grid.Row="0" Grid.Column="2" VerticalAlignment="Center" Width="150" HorizontalAlignment="Left"></TextBox>
<TextBlock x:Name="EmployeeName" Text="Employee Name" FontSize="14" Grid.Row="1" Grid.Column="0" VerticalAlignment="Center"></TextBlock>
<TextBlock x:Name="EmployeeNameSprtr" Text=":" FontSize="14" Grid.Row="1" Grid.Column="1" VerticalAlignment="Center"></TextBlock>
<TextBox x:Name="txtEmployeeName" Text="{Binding EmployeeName, Mode=TwoWay, ValidatesOnDataErrors=True}" Grid.Row="1" Grid.Column="2" VerticalAlignment="Center" Width="150" HorizontalAlignment="Left"></TextBox>
<TextBlock x:Name="EmployeePW" Text="PassWord" FontSize="14" Grid.Row="2" Grid.Column="0" VerticalAlignment="Center"></TextBlock>
<TextBlock x:Name="EmployeePWSprtr" Text=":" FontSize="14" Grid.Row="2" Grid.Column="1" VerticalAlignment="Center"></TextBlock>
<TextBox x:Name="txtEmployeePW" Text="{Binding EmployeePW, Mode=TwoWay, ValidatesOnDataErrors=True}" Grid.Row="2" Grid.Column="2" VerticalAlignment="Center" Width="150" HorizontalAlignment="Left"></TextBox>
<TextBlock x:Name="EmployeeDesg" Text="Designation" FontSize="14" Grid.Row="3" Grid.Column="0" VerticalAlignment="Center"></TextBlock>
<TextBlock x:Name="EmployeeDesgSprtr" Text=":" FontSize="14" Grid.Row="3" Grid.Column="1" VerticalAlignment="Center"></TextBlock>
<TextBox x:Name="txtEmployeeDesg" Grid.Row="3" Text="{Binding EmployeeDesg, Mode=TwoWay, ValidatesOnDataErrors=True}" Grid.Column="2" VerticalAlignment="Center" Width="150" HorizontalAlignment="Left"></TextBox>
<TextBlock x:Name="DepartmentId" Text="DepartmentID" FontSize="14" Grid.Row="4" Grid.Column="0" VerticalAlignment="Center"></TextBlock>
<TextBlock x:Name="DepartmentIdSprtr" Text=":" FontSize="14" Grid.Row="4" Grid.Column="1" VerticalAlignment="Center"></TextBlock>
<TextBox x:Name="txtDepartmentId" Grid.Row="4" Text="{Binding DepartmentId, Mode=TwoWay, ValidatesOnDataErrors=True}" Grid.Column="2" VerticalAlignment="Center" Width="150" HorizontalAlignment="Left"></TextBox>
<TextBlock x:Name="DepartmentName" Text="Department" FontSize="14" Grid.Row="5" Grid.Column="0" VerticalAlignment="Center"></TextBlock>
<TextBlock x:Name="DepartmentNameSprtr" Text=":" FontSize="14" Grid.Row="5" Grid.Column="1" VerticalAlignment="Center"></TextBlock>
<TextBox x:Name="txtDepartmentName" Grid.Row="5" Text="{Binding DepartmentName, Mode=TwoWay, ValidatesOnDataErrors=True}" Grid.Column="2" VerticalAlignment="Center" Width="150" HorizontalAlignment="Left"></TextBox>
<Button x:Name="CancelButton" Content="Cancel" Click="CancelButton_Click" Grid.Row="6" Grid.Column="2" Width="75" Height="23" HorizontalAlignment="Left" />
<Button x:Name="OKButton" Content="Save" Click="OKButton_Click" Grid.Row="6" Grid.Column="0" Width="75" Height="23" HorizontalAlignment="Left" />
</Grid>
Here the SaveUpdateEmp is object of propertyclass in model. How to validate these fields.??
You need to implement INotifyDataErrorInfo on your model and make sure that you have ValidatesOnDataErrors=True on the controls/properties that you need to validate. I can give you a code sample, but I think this does a better job than I can - http://msdn.microsoft.com/en-us/library/system.componentmodel.inotifydataerrorinfo(v=vs.95).aspx. If you have questions, I'm happy to answer.

Listbox No Scrollbar

I have been up and down looking on the internet and many people seem to have this problem but its generally solved by changing the container to a grid, constraining the height etc. etc. I can't to seem to get this to work.
I have an observableCollection thats feeding into a DataTemplate. I can't for th life of me get the scrollbar working. Its there but not enabling. Thanks Scott
<TabItem Header="select a call" x:Name="TabActiveCalls" Style="{DynamicResource MyTabItem}" FontFamily="QuickType">
<Grid Margin="0.125,0.412,3.125,0" Height="471" HorizontalAlignment="Stretch">
<StackPanel Orientation="Horizontal" Width="839.14" HorizontalAlignment="Left" VerticalAlignment="Top" Height="56">
<StackPanel Orientation="Vertical" HorizontalAlignment="Left" Margin="0,0,10,0" Width="741.14">
<StackPanel Height="28" Orientation="Horizontal" Width="733.14" HorizontalAlignment="Left">
<TextBlock x:Name="txtHistoryFound" TextWrapping="Wrap" Text="*" Foreground="#FFE20A0A" Visibility="Collapsed"/>
<TextBlock TextWrapping="Wrap" Text="filter by:" Margin="5,0,10,0" Foreground="#FF585AD4" VerticalAlignment="Center" HorizontalAlignment="Center"/>
<TextBlock TextWrapping="Wrap" Text="call no" Margin="5,0,2,0" VerticalAlignment="Center" Foreground="#FF5E88DA"/>
<TextBox Template="{StaticResource TextBoxBaseControlTemplate}" x:Name="searchCallNo" TextChanged="searchCallNo_TextChanged" TextWrapping="Wrap" Width="67" Foreground="#FF1341B1" TextAlignment="Center" Margin="5,0,10,0" Height="22" VerticalAlignment="Center" />
<TextBlock TextWrapping="Wrap" Text="postcode" Margin="5,0,2,0" VerticalAlignment="Center" Foreground="#FF5E88DA"/>
<TextBox Template="{StaticResource TextBoxBaseControlTemplate}" x:Name="searchPostcode" TextWrapping="Wrap" Width="67" Foreground="#FF1341B1" TextAlignment="Center" Margin="5,0,10,0" Height="22" VerticalAlignment="Center"/>
<TextBlock Height="23" x:Name="txtSiteName" FontSize="16" Foreground="#FF0E7C0B" Width="409" VerticalAlignment="Center" HorizontalAlignment="Left" Margin="0" TextAlignment="Right" Text="Airedale International Ltd" />
</StackPanel>
<StackPanel Width="733.14" HorizontalAlignment="Left">
<Border Height="21" Margin="5,6,8,0" CornerRadius="3,3,0,0" BorderThickness="1" BorderBrush="#FFC0BABA">
<StackPanel Orientation="Horizontal" Background="#FFD0D5DE">
<TextBlock TextWrapping="Wrap" Text="CALL NO. / DATE DUE/ CUSTOMER" Margin="5,0,0,0" Foreground="{DynamicResource ListTitle}" FontSize="10.667" VerticalAlignment="Center"/>
<TextBlock TextWrapping="Wrap" Text="ENGINEER / ADDRESS" Margin="114,0,0,0" Foreground="{DynamicResource ListTitle}" VerticalAlignment="Center"/>
<TextBlock TextWrapping="Wrap" Text="REPORT" Margin="43,0,0,0" Foreground="{DynamicResource ListTitle}" RenderTransformOrigin="2.543,0.429" VerticalAlignment="Center"/>
<TextBlock TextWrapping="Wrap" Text="CALL" Margin="28,0,0,0" Foreground="{DynamicResource ListTitle}" RenderTransformOrigin="2.543,0.429" VerticalAlignment="Center"/>
<TextBlock TextWrapping="Wrap" Text="POSITION" Margin="43,0,0,0" Foreground="{DynamicResource ListTitle}" RenderTransformOrigin="2.543,0.429" VerticalAlignment="Center"/>
</StackPanel>
</Border>
</StackPanel>
</StackPanel>
<Image Height="56" Width="90" Source="/ComfortReportEng;component/Media/Images/comfort_group.png"/>
</StackPanel>
<ListBox ItemTemplate="{StaticResource DataTemplateReportList}" ItemsSource="{Binding Source={StaticResource cvsReportList}}"
Margin="5,56,8,0" MaxHeight="415" Height="415" ScrollViewer.VerticalScrollBarVisibility="Auto" ScrollViewer.CanContentScroll="True"/>
</Grid>
</TabItem>
many thanks for getting back. Here is my DataTempate
<DataTemplate x:Key="DataTemplateReportList">
<Border Margin="0,2,0,0" BorderThickness="1" BorderBrush="#FFA19C9C" CornerRadius="3,3,0,0" Width="810.52" Height="50" >
<Grid Background="#FF737B89" Height="48" >
<StackPanel Orientation="Vertical" HorizontalAlignment="Left" Width="274" VerticalAlignment="Top" >
<StackPanel Height="23" Orientation="Horizontal" Margin="0">
<TextBlock TextWrapping="Wrap" Text="{Binding CallNo, Mode=TwoWay}" Foreground="#FF7DF51E" Margin="5,0,0,0" FontFamily="Verdana"/>
<TextBlock TextWrapping="Wrap" Text="{Binding DateDue, Mode=TwoWay, StringFormat=d}" Foreground="White" Margin="5,0,0,0" FontFamily="Verdana"/>
</StackPanel>
<StackPanel Height="23" Orientation="Horizontal">
<TextBlock TextWrapping="Wrap" Text="{Binding CompanyName, Mode=TwoWay}" Foreground="#FFFFEA00" Margin="5,0,0,0" FontFamily="Verdana"/>
</StackPanel>
</StackPanel>
<StackPanel HorizontalAlignment="Left" Width="456" Orientation="Vertical" Height="46" Margin="274,1,0,1" VerticalAlignment="Top">
<StackPanel Height="23" Orientation="Horizontal">
<TextBlock TextWrapping="Wrap" Text="{Binding EngineerName, Mode=TwoWay}" Foreground="#FFCAE5C6" Margin="5,0,0,0" FontFamily="Verdana" Width="140"/>
<TextBlock TextWrapping="Wrap" Text="{Binding ReportStatus, Mode=TwoWay}" Foreground="#FF7DF51E" Margin="20,0,0,0" FontFamily="Verdana" Width="50"/>
<TextBlock TextWrapping="Wrap" Text="{Binding CallStatus, Mode=TwoWay}" Foreground="#FF7DF51E" Margin="20,0,0,0" FontFamily="Verdana" Width="50"/>
<TextBlock TextWrapping="Wrap" Text="{Binding Position, Mode=TwoWay}" Foreground="White" Margin="20,0,0,0" FontFamily="Verdana" Width="50"/>
</StackPanel>
<StackPanel Height="23" Orientation="Horizontal">
<TextBlock TextWrapping="Wrap" Text="{Binding Address, Mode=TwoWay}" Foreground="#FFFFEA00" Margin="5,0,0,0" FontFamily="Verdana" Width="483.12"/>
</StackPanel>
</StackPanel>
<Grid Width="56" HorizontalAlignment="Right" Margin="0,0,12.52,0" VerticalAlignment="Top">
<Image Name="imgInfo" Source="/ComfortReportEng;component/Media/Images/Info4.png" Margin="24,8,0,0" Cursor="Hand" MouseLeftButtonDown="imgInfo_MouseLeftButtonDown"/>
</Grid>
</Grid>
</Border>
</DataTemplate>
Must be a bug. I have the following only..
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="ComfortReportEng.Views.EngineerReport.EngineerReport"
Title="Engineer Report" WindowStartupLocation="CenterScreen" Loaded="Window_Loaded" SizeToContent="WidthAndHeight" >
<Window.Resources>
<CollectionViewSource x:Key="cvsReportList"/>
</Window.Resources>
<Grid Margin="0.125,0.412,3.125,0" Height="471">
<ListBox Margin="23,64,3,0" Width="834.14" ItemsSource="{Binding Source={StaticResource cvsReportList}}"
x:Name="lbReportList" SelectionChanged="lbReportList_SelectionChanged" Background="#FFEEEFE4" />
</Grid>
and code is
private void LoadReportList()
{
int number = 0;
List<int> myNumbers = new List<int>();
while (number < 80)
{
myNumbers.Add(number);
number += 1;
}
_cvsReportList = (CollectionViewSource)(this.FindResource("cvsReportList"));
_cvsReportList.Source = myNumbers;
}
This was copied over from another project. Completely confused. Please don't worry. It's not a logical problem. Please take this as a close call with no solution. Cheers again Scott
Just to give this completeness. I am not sure why this happens but here is it.
if (System.Environment.MachineName == "SCOTT-PC")
{
this.txtUserName.Text = "Scott Fisher";
this.txtPassword.Password = "palace";
//LoginOK();
}
else
Keyboard.Focus(this.txtUserName);
If I clear the comments on LoginOK procedure I will get no scrollbar. With it commented and I interact with the login screen then everything is fine. Finally here is the code for the LoginOK.
if (LoginService.CheckLogin(txtUserName.Text, txtPassword.Password.ToString()))
{
Helpers.User.ThisUser = this.txtUserName.Text;
EngineerReport.EngineerReport engReport = new EngineerReport.EngineerReport()
{
Owner = Window.GetWindow(this),
WindowStartupLocation =
System.Windows.WindowStartupLocation.
CenterOwner
};
this.Hide();
engReport.ShowDialog();
}
else
{
this.txtPassword.Password = "";
this.txtPassword.Focus();
}
Can you provide you DataTemplate as I believe I have just managed to mock up what you are trying to achieve and I have scrollbars visible and working form the start.
Here is the xaml that I used for the DataTemplate for the ListBox:
<ListBox DataContext="{StaticResource MusicData}" ItemsSource="{Binding XPath=Album}">
<ListBox.ItemTemplate>
<DataTemplate>
<ListBoxItem>
<StackPanel Orientation="Horizontal" >
<TextBlock>No.</TextBlock>
<TextBlock Text="{Binding XPath=No}"></TextBlock>
<TextBlock>Title</TextBlock>
<TextBlock Text="{Binding XPath=Title}"></TextBlock>
</StackPanel>
</ListBoxItem>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
Hope this helps.
I also found a piece of code I used a while back and this might help. You can try setting the ItemsPanelTemplate:
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel>
<ScrollViewer VerticalScrollBarVisibility="Visible" />
</StackPanel>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
This will work with any items control as stated in this article:
http://msdn.microsoft.com/en-us/library/system.windows.controls.itemscontrol.itemcontainerstyle.aspx
One final thing I can suggest is to create your own ControlTemplate for the ListBox Like so:
<ListBox.Template>
<ControlTemplate>
<ScrollViewer VerticalScrollBarVisibility="Auto">
<ItemsPresenter />
</ScrollViewer>
</ControlTemplate>
</ListBox.Template>

Categories

Resources