Contents tagged with .NET

  • Adhoc testing of .NET RIA Services

    Suddenly my Silverlight 3 application breaks during development process. Cause I have installed Visual Studio 2010 a few hours before, I was sure: must be something with 2010. After uninstall and reinstall SP1 everything worked fine, except .NET RIA services :-(

    Read more...

  • Silverlight 3 Beta to RTW changes

    It is very important that your applications are ready for Silverlight 3. If you have developed with the Beta bits you have to do a lot of changes to get ready for RTW. There exists a document changes.docx which I can not find at the moment. For that reason I decided to make a copy public on my private server.

    If you run a Silverlight 2 application no action is necessary. The SL3 plugin can host SL2 applications. So there are no breaking changes between 2 and 3!

    There are a set of bugs fixed in SL 3 related to SL 2. For compatibility reasons Silverlight plugin detects and change to quirks mode running SL 2 applications in a bug friendly mode.

    [Update]thanks to Tim Heuer: link is http://msdn.microsoft.com/en-us/library/cc645049(VS.95).aspx. Saves traffic on my server ;-)

    [/Update]

    Read more...

  • Silverlight 2.0 Compression Rate

    After a short discussion in silverlight forums with a guy who have only 19kb line, I checked out compression for XAP files. A XAP is a zipped package of DLL’s and resources. With winrar installed you can open by context menu from Visual Studio Explorer the xap (clientbin). It contains files like

    image

    The size of the package in this case is 750 KB. I unzipped the content and compressed it with Winrar again and- surprise- surprise, package size is now 547 KB. A reduction more than 35%. Only rename the zip back to xap.

    I will investigate a little bit, how to automate that within the build process.

    Read more...

  • B# and Silverlight Isolated Storage

    I am a VB developer. As most of expert coder are using C# I must step forward. B# is the language which can be written by VB guys and make it readable for C# gurus. Today's topic is the data store of Silverlight on client side- isolated storage.

    Read more...

  • Input Validation with Silverlight

    I miss ASP.NET. With the 2.0 Microsoft had the world best technology for creating applications of all kind. Small or large, ASP.NET 2.0 have features for all. Now several years later we have Silverlight 2 (no 2.0) and should be good as ASP.NET 2.0!? I don't think so- Silverlight have some great advantages but even more missing features. And some of them essential and important.

    For me user input validation is one of them. To get the right data from user in correct format is a huge challenge and costs a lot of development time. ASP.NET have rich and easy validator controls to do the job. Silverlight have not.

    But Input validation must done, so how? I will show you my approach. First of all, where to validate?

    • Database
    • Data Layer
    • UI Layer
    • User Interface
    • Nowhere

    I don't like typing things several times. I hate to make data access and type field name 10 times in table, properties and UI. I like the drag and drop stuff and get declaration of where and how my data comes. (no dataset at all ;-)).  Silverlight doesn't have that by design and by architecture. The design part comes from Microsoft they have not enough resources to implement every feature within some weeks.

    Second problem with data validation comes from loosely connected systems. The user interface is fare fare away from database. Sometimes thousands of km/ miles are between them. Proxy server, hubs, switches even different protocols and ports. So from that view it doesn't make sense to get data schema each time from table and reuse it in UI.

    Input validation rules must be declared physical narrow to user interface. The closest thing I can imaging is within the same memory address space.

    The practice

    Cause of disliking typing code I use a ADO.NET Entity model and a ADO.NET Dataservice to get the data. Visual Studio 2008 creates a proxy class (reference.vb) for the Silverlight project. Database is northwind with table customer. The goal is a input dialog. Phone number is limited to 20 characters. Error is shown as tooltip (zu lange). Textfield is marked as read. Tabbing out will do the validation.

    First of all I create the rule set. I do that in the created proxy class (reference.vb) and check the length and throw an exception.

    Public Property Phone() As String
            Get
                    Return Me._Phone
            End Get
            Set
                    If Len(value) > 20 Then
                        Throw New Exception("zu lange")
                    End If
                    Me.OnPhoneChanging(value)
                    Me._Phone = value
                    Me.OnPhoneChanged()
            End Set
    End Property

    Not the best solution. If somebody is updating service reference, your code will be overwritten.

    The databinding in the Textbox must have twoway binding and two additional attributes set. That is necessary to get a special event in error case (exception) which will defined in next step

    <TextBox Margin="8,8,144,8" Grid.Column="1" Grid.Row="3" 
    Text="{Binding Phone,Mode=TwoWay,NotifyOnValidationError=true,  
    ValidatesOnExceptions=true}"/>

    Then we can create the code for the event BindingValidationError of the grid, named Layoutroot. I decided to show the exception message as tooltip and to change backcolor of Texbox. eventargs gives reference to Textbox and also to eventaction (Added, Removed)

    Private Sub LayoutRoot_BindingValidationError(ByVal sender As System.Object, 
    ByVal e As System.Windows.Controls.ValidationErrorEventArgs)
         If e.Action = ValidationErrorEventAction.Added Then
                CType(e.OriginalSource, TextBox).Background = _
    New SolidColorBrush(Colors.Red)
                ToolTipService.SetToolTip(CType(e.OriginalSource, TextBox), _
    e.Error.Exception.Message)
         Else
                CType(e.OriginalSource, TextBox).Background = _
    New SolidColorBrush(Colors.White)
         End If
    End Sub

    Full code for completion

    Partial Public Class page29
        Inherits UserControl
        Dim cust As ServiceReference1.NorthwindEntities = _
    New ServiceReference1.NorthwindEntities(New Uri("WebDataService1.svc", UriKind.Relative)) Public Sub New InitializeComponent() End Sub Private Sub page29_Loaded(ByVal sender As Object,
    ByVal e As System.Windows.RoutedEventArgs) Handles Me.Loaded cust.BeginExecute(Of ServiceReference1.Customers)_
    (New Uri("Customers", UriKind.Relative), AddressOf fertig, cust) End Sub Public Sub fertig(ByVal result As IAsyncResult) LayoutRoot.DataContext = _
    cust.EndExecute(Of ServiceReference1.Customers)(result).First End Sub Private Sub LayoutRoot_BindingValidationError(ByVal sender As System.Object,
    ByVal e As System.Windows.Controls.ValidationErrorEventArgs) If e.Action = ValidationErrorEventAction.Added Then CType(e.OriginalSource, TextBox).Background = _
    New SolidColorBrush(Colors.Red) ToolTipService.SetToolTip(CType(e.OriginalSource, TextBox),
    e.Error.Exception.Message) Else CType(e.OriginalSource, TextBox).Background = _
    New SolidColorBrush(Colors.White) End If End Sub Private Sub Button_Click(ByVal sender As System.Object,
    ByVal e As System.Windows.RoutedEventArgs) Dim o As ServiceReference1.Customers = LayoutRoot.DataContext cust.UpdateObject(o) cust.BeginSaveChanges(AddressOf saveFertig, o) End Sub Public Sub saveFertig(ByVal result As IAsyncResult) cust.EndSaveChanges(result) End Sub End Class

    Read more...

  • Silverlight Multiselect Listbox

    The Listbox control of Silverlight 2 have no multi selection. Datagrid have! I want to show how to build a Listbox with Checkboxes and iterate at the end through all items an see if they are checked. Seams to be easy!?

    Read more...

  • ADO.NET Dataservices: Fancy Error Part II

    Today my first Silverlight 2 application goes live. It is a customer feedback app for the ADC 08 conference. After successfully installed and tested a few hours everything went well. But then data was not show. on direct call of ado.net dataservice vcs in browser following error comes up

    Read more...