Skip to main content
Home Forums General Silverlight Getting Started Some layout questions..
4 replies. Latest Post by Inx on August 25, 2009.
(0)
Inx
Member
1 points
3 Posts
08-25-2009 5:36 AM |
Hi!
First of all I want to create a ScrollPanel(ScrollView) which I sort of know how to do..but inside that scrollview I want to have a Grid so I can list other controls in that grid..sort of as a table in HTML..and I tried creating a Grid in the ScrollView for just a few secounds ago..but then once I added a ProgressBar into the Grid the behind C#-code started to throw an error saying that there where no such object instance...even though the visual studio intellisense showed my progressbars instance name and I also checked the x:Name of my progressbar a few time and everything seemed to be fine.
After that I moved out the progressbar from the Grid and placed it at the very root("LayoutRoot")..and for some reason al of a sudden the progressbar worked!
But since I need a way of listing a bunch of progressbars at the same time in a list, the way of putting them all in the LayoutRoot just wont do it.
I hope you understand the problem, cause its kind of tricky to explain...
So well...how should I create something that holds some progressbars for me, and also make those progressbars avaible in the code-behind?
Thanks in advance!
codeblock
Contributor
4060 points
716 Posts
08-25-2009 5:50 AM |
can you provide a short sample of code?
08-25-2009 6:46 AM |
What Im trying to create is a basic fileuploader with a progressbar, and Im also trying to make it possible to upload more then one file at the same time..thats why need a way to display the progressbars in some sort of "table"/Grid
At the current code belove Im simply trying to make the progressbars value to increse once you press the btnUploadFile button..but as mentioned..if you run this in visual studio you get an error saying that there is no such object as btnUploadFile...I should mention aswell that I new to Silverlight...I started doing some apps and have learned the very basics of expression blender, but I have worked with C# and ASP.net and such for a while now..so Im not that new to everything.. just so you know incase I have done something badly wrong here..
xaml
<UserControl xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:dataInput="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data.Input" xmlns:controls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls" x:Class="ProgressBar.MainPage" Width="640" Height="480"> <Grid x:Name="LayoutRoot"> <ContentPresenter Height="100" Margin="0,0,113,10" VerticalAlignment="Bottom"> <ScrollViewer x:Name="inProgressViwer" BorderBrush="{StaticResource ContentControlersBorder}" Margin="0,-371,0,-9"> <Grid x:Name="ProgressGrid" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" ShowGridLines="True"> <Grid.ColumnDefinitions> <ColumnDefinition Width="0.8*"> </ColumnDefinition> <ColumnDefinition Width="0.2*"> </ColumnDefinition> </Grid.ColumnDefinitions> <Grid.RowDefinitions> <RowDefinition> </RowDefinition> <RowDefinition> </RowDefinition> <RowDefinition> </RowDefinition> <RowDefinition> </RowDefinition> <RowDefinition> </RowDefinition> <RowDefinition> </RowDefinition> <RowDefinition> </RowDefinition> </Grid.RowDefinitions> <ProgressBar x:Name="ProgressBar1" Maximum="100" Width="380" Height="20"></ProgressBar> </Grid> </ScrollViewer> </ContentPresenter> <Button Height="32" HorizontalAlignment="Right" Margin="0,6,10,0" VerticalAlignment="Top" Width="94" Content="Choose file"/> <Button x:Name="btnUploadFile" Height="32" HorizontalAlignment="Right" Margin="0,44,10,0" VerticalAlignment="Top" Width="94" Content="Upload file"/> </Grid></UserControl>
Code-behind(C#)
using System;using System.Windows;using System.Windows.Controls;using System.Windows.Documents;using System.Windows.Ink;using System.Windows.Input;using System.Windows.Media;using System.Windows.Media.Animation;using System.Windows.Shapes;namespace ProgressBar{ public partial class MainPage : UserControl { Storyboard _sboard = new Storyboard(); public MainPage() { InitializeComponent(); _sboard.Duration = TimeSpan.FromMilliseconds(10); _sboard.Completed +=new System.EventHandler(_sboard_Completed); Loaded +=new System.Windows.RoutedEventHandler(MainPage_Loaded); } private void MainPage_Loaded(object sender, System.Windows.RoutedEventArgs e) { btnUploadFile.Click +=new System.Windows.RoutedEventHandler(btnUploadFile_Click); } private void btnUploadFile_Click(object sender, System.Windows.RoutedEventArgs e) { _sboard.Begin(); } private void _sboard_Completed(object sender, System.EventArgs e) { if (ProgressBar1.Value < ProgressBar1.Maximum) { ProgressBar1.Value++; } } }}
08-25-2009 8:33 AM |
The problem come from the ContentPresenter element. If you remove it the code works fine. The ContentPresenter is usually used as a placeholder in control templates and the runtime does not recognize controls inside of it.
bye
08-25-2009 9:03 AM |
Yeah! That did the trick :)..thanks!