Where is IPagedCollectionView?

This is nothing but a sticky note for me than a post. I downloaded a project and when I tried compiling the project I got an error from the compiler that it couldn’t find IPagedCollectionView. I checked the name space of the class in my other box and it pointed me to System.ComponentModel, I checked the references and I do have that dll. (One thing I did not check was to double click open the reference and see if the class definition there). Anyway, I went directly to the trusted source regarding these kind of problems, Microsoft msdn web site and found the missing dll. Even though the name space points to System.ComponentModel. the class definition is in System.Windows.Data.dll. So for future reference if you run into this problem, now you know, where it is 🙂

http://msdn.microsoft.com/en-us/library/system.componentmodel.ipagedcollectionview(VS.95).aspx

Dynamically change UI Element in Silverlight

I ran into a situation where, based on what grid client wants to see, I need to show them that particular grid of user’s choice. The catch here is that, all the grids are different third party controls so I can not generalize and create one view, instead each grid will be separate view. Here is how I went about doing it. I have main page XAML, which has a combo box which will allow the user to select which grid they want to see. By default, we show the first grid on load. When the grid selection changes I need to replace the current grid with selected grid.

Following is main page XAML.

<Grid x:Name="LayoutRoot" Background="White">
    <Grid.RowDefinitions>
        <RowDefinition Height="5*"/>
        <RowDefinition Height="95*" />
    </Grid.RowDefinitions>

    <ComboBox Name="comboSelection" SelectionChanged="comboSelection_SelectionChanged" Width="300" HorizontalAlignment="Left" Grid.Row="0">
        <ComboBoxItem Content="First" IsSelected="True"/>
        <ComboBoxItem Content="Second"/>
        <ComboBoxItem Content="Third"/>
    </ComboBox>
    <sdk:DataGrid AutoGenerateColumns="False" Grid.Row="1" HorizontalAlignment="Left" Margin="0,0,0,0" Name="dataGrid1" VerticalAlignment="Top" />
</Grid>

 

Now I create two other XAML with data grid in it call it First and Second. A Sample First XAML looks like this

<Grid x:Name="LayoutRoot" Background="White">
        <sdk:DataGrid AutoGenerateColumns="True" HorizontalAlignment="Left" Name="dataGrid2" VerticalAlignment="Top" />
    </Grid>

in the code behind, I load some data and data bind it to datagrid2. The interesting part of the code which replaces the default grid from the main page is as follow

FirstControl first = new FirstControl();
LayoutRoot.Children.RemoveAt(1);
LayoutRoot.Children.Add(first);
Grid.SetRow(first, 1);

So create the first grid and remove the existing grid from row 1, add the newly created as a child to the Layout Root. Make sure you set which row the newly added grid has to go to. That’s it. Now you can switch in and out of grid as you want.

Technorati Tags: ,,

Getting focus on Silverlight control on load

When we host a Silverlight application inside a ASP.Net page and set a focus on a control inside Silverlight application, we would except the control to get the focus, but that does not happen automatically. One way it can be achieved by adding a on load script to the Silverlight object and make the Silverlight object get the focus.

<param name=”onLoad” value=”onLoad” />

function onLoad(sender, args)

{

   var silverlightObject = document.getElementById(“silverlightObject”);

   if (silverlightObject != null)

      silverlightObject.focus();

}

make sure you name the Silverlight object as ‘silverlightObject’ or replace the onload script with the name of the silverlight object.

Technorati Tags: ,

RAD development in SL4

It is very easy to develop a simple silver light page which does not have any complicated logic without writing a single line code (as my friend put it). Yes it is very easy. But there is another question, if you are simply displaying a data from data source then do you need to follow MVVM model? You could but I do not think it is required since there is no code involved in VM. This is simple forms over data pattern.

In SL4, at your server side, create the Data Model and associate it with a service.  Build the solution. Now go to the client side and under Data there is an option to show the Data Source. From the data source, under domain services, drag the data service you want and drop in the grid control, whola that is it. Now if you run the program it will show you a simple data grid with the data from the domain service.

Couple of things you have remember if you are going in this path. The first and foremost, is the authentication and authorization.  If you do not care about the authorization then you are ok, if not, build the base authorization service and reuse it in all the domain services by adding [RequiredAuthentication] attribute. In the client side also create the main page which knows user information and passes to authentication service before you do data binding.

Second issue that you might run into is the amount of data that is passed over wire. So apply some filtering to the data before you return all the data. You can do the filtering at the server side or on the client side. You can do the filtering in the XAML itself. The simple solution is to add the filter based on some controls. By adding some controls, which binds the values to filtering logic in the data grid will bring only the data you want to show. You can read more about how to apply filtering on XAML at this link.

Technorati Tags: ,

no ‘InitializeComponent’ does not exist in the current context

Today I created a simple Silver Light 4 application and copied a XAML and couple of classes from my existing project. Changed all the references of the old name spaces to new name space and compile it and I got this error. It took me 10 minutes to figure out what was the problem. Simple, I missed one namespace which was still pointing to the old namespace. So if you run into this error message, most probabily you missed one or more name space references to old name space. It seems some other people run into the same problem, if you do not have ‘CompileXAML’ option not set in the MSBuild.

SL3 + RIA custom authentication

I have been playing with Custom Authentication lately and while trying out, I ran into bunch of problem. So I thought I will point out few of things you need to watch out. When you create a SL3 + RIA services, it automatically gives you Windows Authentication. When you need to change to custom authentication, couple of things you need to change and for that I would recommend Brad Abrams (ex-Microsoft) blog

If you are new to this area I would strongly recommend you to look at the authentication quick starts in the following URL, they are very simple and easy to follow.

http://code.msdn.microsoft.com/RiaServices

while you are at it, I would recommend visiting this Silverlight forum question to have an understanding of authentication as well.

Few things to watch out are

1. Make sure you have <authentication mode="Forms" /> in your web.config at the WCF service side.

2. The USER return from GetAuthenticatedUser has a catch, if you do not assign the name to the returning user, then by default IsAuthenticated flag will be false.

3. Make sure you have authentication setup to form authentication in silver light app.xaml.

<local:WebContext.Authentication>
                <appsvc:FormsAuthentication></appsvc:FormsAuthentication>
</local:WebContext.Authentication>

4. If you have a page where you are authenticating and then data binding, do not do data binding till you complete the validation. In other words, make sure you add the root visual element on login completed method delegate.

If you run into any other problems let me know or if you have any comments or suggestion also send me a mail.