Friday, July 23, 2010

Ria Services And Odata

When adding a Domain Service Class  (RIA) to a Silverlight project (the Web project),  a dialog titled Add New Domain service Class appears. In this dialog you can select via a checkbox to expose Odata endpoint.

Depending on you selection, the code generated for the Silverlight client will be different. If you look in the Silverlight Generated Code folder (Show all folders on the solution explorer) open the projname.web.gs file and note the following differences:

If OData not checked, 2 namespaces are generated: ProjName and ProjName.Web. If Odata is checked you get 3 namespaces: ProjName, ProjName.Web.Views, ProjName.Web.Models.

Wednesday, June 30, 2010

Silverlight Toolkit Theme Controls

I downloaded the Silverlight toolkit from http://silverlight.codeplex.com/releases/view/43528 (Silverlight_4_Toolkit_April_2010.msi). When I ran the msi, and subsequently opened Visual studio 2010, in the toolbox under the tab "All Silverlight Controls" I found several "Theme Controls" such as BubbleCremeTheme, RainierOrangeTheme etc.

These can be used as controls rather easily. For example, open a new Silverlight application. On MainPage.xaml select a theme control from the toolbox and drag it onto the design surface. This causes a reference to be added to the Silverlight project for the associated theme control (System.Windows.Controls.Theming.BubbleCreme).

I used the XAML tab to get the xaml to look like the following:

<grid name="LayoutRoot" background="White">
<?xml:namespace prefix = toolkit />
<toolkit:bubblecremetheme name="BubbleCremeTheme1">
<toolkit:bubblecremetheme.content>
</toolkit:bubblecremetheme.content>
</toolkit:bubblecremetheme>
</grid>

I added some controls to <toolkit:bubblecremetheme.content>. An example follows:

<grid name="LayoutRoot" background="White">
<toolkit:bubblecremetheme name="BubbleCremeTheme1">
<toolkit:bubblecremetheme.content>
<grid>
<button name="Button1" type="submit" content="Button" height="23" horizontalalignment="Left" margin="56,30,0,0" verticalalignment="Top" width="75">
<checkbox content="CheckBox" name="CheckBox1" height="16" horizontalalignment="Left" margin="58,62,0,0" verticalalignment="Top">
</grid>
</toolkit:bubblecremetheme.content>
</toolkit:bubblecremetheme>
</grid>

The themes are encapsulated in the associated control (System.Windows.Controls.Theming.BubbleCreme) - they should be treated like any other control when used. During my experimentation I had to switch between design and xaml views in Visual Studio 2010 to get the xaml just right.

Xaml source for the themes are available and can be found at the installation path for the Silverlight 4.0 toolkit: (on my Windows 7 64 bit machine: C:\Program Files (x86)\Microsoft SDKs\Silverlight\v4.0\Toolkit\Apr10\Themes\Xaml)

Friday, June 25, 2010

ODATA

After attending the OData roadshow in Chicago a few weeks ago I have been inspired to learn and practice OData. After some absence from the blogging world, I decided to write some entries about my experiences.

My very first comment about OData--it is awesome, exposing data with ease, improving and streamlining application development.

I also have done some work with RIA (domain services). During my learning cycle I found that a RIA domain service can also be exposed as Odata. When creating the domain service be sure to check "Expose OData endpoint" check box.

Then through the browser you can access the domain service as an odata endpoint.

It took me awhile to actually get this to work, as most of my problems were syntax related.

Here is what I learned: to access an OData endpoint that is a RIA domain service in a Silverlight project (4.0) the following should work:

If your Silverlight Web project is named: SilverlightApplicationSimpleRIA.Web

Then the link to access the OData endpoint is:
http://localhost:2551/SilverlightApplicationSimpleRIA-Web-DomainServiceNW_RIA.svc/OData/

Notice
1) . (period) is replaced with a - (In web project name)

2) appended to the project name SilverlightApplicationSimpleRIA-Web is a - and then the name of the Domain Service (as defined in the Web project), followed by .svc, followed by a /
i.e. SilverlightApplicationSimpleRIA-Web-DomainServiceNW_RIA.svc/
Be aware that the "silverlight web" project has no .svc file defined, this is constructed "virtually" for a domain service

3) then add OData/ (the syntax here caused me a bit of a problem--OData is case sensitive -- also do not forget the ending / (if you do you'll probably get endpoint not found message when doing the access)

I tested this with IE 8 along with Silverlight 4, and it worked like a champ.

Thursday, July 26, 2007

WPF & Datargidview Control

The Windows Forms DataGridView control may be hosted in a WPF form using a <WindowsFormsHost> tag
(in fact any Windows Forms Control may be hosted within this tag, which provides a solution to the lack of a WPF Data Grid control).

The following XAML and VB.Net code was done using Visual Studio 2005 .

In a WPF Windows application:
  • add a reference to WindowsFormsIntegration (WindowsFormsIntegration.dll)
In a XAML file (i.e. Window1.xaml)
  • add a reference to System.Windows.Forms:
<Window
xmlns:wf="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms" ...

  • add the following XAML to host the DataGridView control

<StackPanel>

<WindowsFormsHost Width="200" Height="200">

<wf:DataGridView x:Name="dgv"> </wf:DataGridView>

</WindowsFormsHost>

</StackPanel>

Note: it appears that the <WindowsFormsHost> should have Width and Height attributes to ensure that the DataGridView will render with scrollbars

  • Build the Project

In the associated code view for the XMAL(Windows.xaml.vb) :

  • Add the following code to the Window1_Loaded event handler:

'Use the Authors table in the Pubs database

Dim conn As New System.Data.SqlClient.SqlConnection("integrated security=true;database=pubs")

Dim da As New System.Data.SqlClient.SqlDataAdapter("select * from employee", conn)

Dim ds As New System.Data.DataSetda.Fill(ds)
Me.dgv.DataSource = ds.Tables(0)

Me.dgv.DataMember = ds.Tables(0).TableName

Me.dgv.ScrollBars = System.Windows.Forms.ScrollBars.Both

Me.dgv.Visible = True

Run the program to display the WPF with the DataGridView.

Note that <WindowsFormsHost> may only contain one Windows Forms Control. Use multiple <WindowsFormsHost> tags or create a Windows Forms User Control with the desired layout and host in using in <WindowsFormsHost>. Also, the DataGridView will not render with any WPF styles that may have defined.

Sunday, July 08, 2007

Flow Documents and Code Behind

It is possible to have XAML controls with event handlers in a Flow Document. This can be accomplished using Visual studio 2005 by:

  • Add a FlowDocument (WPF) to a Visual Studio 2005 .NET 3.0 WPF project (i.e. FlowDocument2.xaml)
  • Add a class to the project named FlowDocument2.xaml.vb (VS 2005 does not automatically add an associated "code-behind" class)
  • In FlowDocument2.xaml in the <FlowDocument> element add the attribute: <FlowDocument a:Class="FlowDocument2" ....
  • Within a <Paragraph> element add:
    Test Text<InlineUIContainer><Button Name="TestCmd" Content="Press Me"></Button></InlineUIContainer>Test Text
  • Build the project
  • In the Code-behind class (FlowDocument2.xaml.vb) for TestCmd (the button) add a click event
  • In the click event place some code (i.e. MessageBox.Show("clicked")
  • Make FlowDocument2.xaml the startup URI for the project
  • Run the project (F5 or <Shift>F5

Labels:

XAML & Flow Documents

For WPF projects in Visual Studio 2005 you can have the project display a Flow Document when starting.

In the App.Xaml file, for the < Application> element add the following attribute:

StartupUri="FlowDocument1.xaml"

With this approach it is easy to see what the associated flow document looks like. Just run the project using F5 (Start Debugging) or <Shift> F5 (Start Without Debugging).

Note that Flow Documents cannot be viewed in design mode within Visual Studio 2005, so this technique provides an easy way to see the actual formatting of a Flow Document.

Sunday, April 22, 2007

WPF and Windows Forms

While learning WPF, in order to take advantage of its neat features (i.e graphics, animation etc), you will most likely want to get busy using WPF in your projects as soon as possible. You can do this even if you are not up to speed on all WPF features.

It is possible to have both WPF Windows and traditional Windows Forms within the same VS 2005 .NET Framework 3.0 Windows Application (WPF). You can use WPF forms where you feel comfortable, but use Windows Forms for other situations.

For example, suppose that you have not yet got up to speed with WPF data binding -- you could implement that in a Win Form using the traditional data binding techniques, but do other application interfaces using WPF (i.e About Form, Search Form).


In .NET code, both WPF Windows and Windows Forms are objects and can be thought of as a "form"

For example:
Dim f as SomeForm 'could be a WPF or Win Form
f.show

You can show a WPF form from a Windows Form or show a Windows Form from a WPF form.

Saturday, April 21, 2007

Some Beginning XAML

XMAL gives developers the means to customize their user interfaces in ways that have not been available using traditional tools (i.e. Windows Forms).

The following XMAL snippet gives a simple example:

<StackPanel Background="Beige">

<Button>

<Button.ToolTip>
<TextBlock FontWeight="UltraBold" TextAlignment="Center">
<Ellipse Width="20" Height="20" Stroke="Blue" Fill="AliceBlue"></Ellipse>
<Label>A ToolTip Message</Label>
<Rectangle Height="20" Width="20" Fill="AliceBlue" Stroke="Blue" StrokeThickness="2" ></Rectangle>
</TextBlock>
</Button.ToolTip>

<Button.Content>
<TextBlock FontWeight="UltraBold" TextAlignment="Center">
<Ellipse Width="20" Height="20" Stroke="Red" Fill="Pink"></Ellipse>
<Label>Press Me</Label>
<Rectangle Height="20" Width="20" Fill="Pink" Stroke="Red" StrokeThickness="2" ></Rectangle>
</TextBlock>
</Button.Content>

</Button>
</StackPanel>

The button defines its own content and a tooltip. Notice that the content and tool tip defintions can contain other XAML, allowing for very interesting presentation. Here, both the button and tool tip have tradtional text (i.e. Press Me) as well as a Rectangle and Ellipse. No longer are developers constrained by text only or creating their own images with hope that a control supports display of an image.

The other good news is that when the window with the above is resized, the button contents are automatically adjusted to ensure that it continues to have a consistent look and feel -- and the best part, a developer does not have to do anything to get this behavior!!