I’m a Java developer whose inherited a web project from another team whose sole developer upped and quit. The majority of the project is written in Spring, JSPs and jQuery, however there is one component that is a Silverlight XAP.
Of course, the project was just handed to me and we’re already having production issues with it. I’ve never written a lick of C# before, and am scrambling to try and fix this as fast as humanly possible.
This is a Microsoft VS 2010 (Pro Edition) C# solution project, with a presentation layer consisting of XAML and CS files. The component that needs to be fixed is a file uploader that allows users to choose 1+ files from their machine and place them in a “queue” (a listbox). Then, with the click of a single button, all the “queued” files get uploaded to our server.
I need to be able to tell when the listbox is empty (when there are 0 files queued/populating it). This feature is represented in the code by a XAML/CS pair of files named ListItemControl.xaml and ListItemControl.xaml.cs respectively.
Here is the beginning of the CS file:
namespace silv.Uploader
{
public partial class ListItemControl : UserControl
{
private UserFile UserFile { get { return (UserFile)this.DataContext; } }
public ListItemControl()
{
InitializeComponent();
...
Applying Java concepts to its C# cousin (as I’ve been told), this looks like my ListItemControl is an in-house class extending a Microsoft built-in type of System.Windows.Controls.UserControl. Furthermore, that it has a UserFile property (which I assume is another homegrown type) representing a file or set of files that needs to be uploaded.
So first, as a sanity check: can someone please confirm those assumptions above?!?
First off, in Java/Swing-land, you would instantiate or subclass a JList (listbox) type, which has built-in methods/models to determine the number of items populating it at any given time.
What is the ListItemControl/UserControl equivalent in C#-land?
In this CS file I don’t see any methods for determining size/length/counts of data. Same when I F12 (Go to Definition) UserControl.
Essentially, I’m asking here: how do I query this listbox component for the number of items it is populated with? Thanks in advance for any nudges in the right direction…
Edit: Below is a snippet of the XAML that I believe is responsible for initializing this listbox:
<ScrollViewer Grid.Row="1" x:Name="svFiles" IsEnabled="True" ScrollViewer.VerticalScrollBarVisibility="Visible" Margin="0,1,18,252">
<StackPanel x:Name="stkMain" Orientation="Vertical" VerticalAlignment="Stretch">
<ItemsControl x:Name="icFiles" KeyUp="ScrollViewer_KeyUp" >
<ItemsControl.ItemTemplate>
<DataTemplate>
<local:ListItemControl ScrollViewer.VerticalScrollBarVisibility="Visible" />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</StackPanel>
</ScrollViewer>
The updated snippet seems to be the right piece of XAML – you have the
ItemsControl, which is a generic repeater control for rendering a collection of items. What I still don’t see is where the items are added, but that might be somewhere else in the code.However, since the
ItemsControlis given a name, so you can access that:Where exactly are you trying to access the queue length? This needs to be in the code-behind of the window that the
ItemsControlis defined in.