The folks at SQL Bits are wanting a new logo and are holding a competition.
I thought it was about time, I submitted my own entry (I hope it wins).
Anyways my entry is below:
My ramblings in Silverlight, Windows Azure, .NET, ASP.NET, C# (all the way from the UK) A little place where i can store the snippets of information, which usually get lost in my tiny little brain, and will now forever remain enshrined in the google archives forever.
The folks at SQL Bits are wanting a new logo and are holding a competition.
I thought it was about time, I submitted my own entry (I hope it wins).
Anyways my entry is below:
I thought I'd post up a Silverlight Beta 2 dynamic XAML sample. This is a pretty simple sample which consists of a textbox, a button and a grid.
All you simply do is paste some XAML into the textbox, click the button and the XAML will appear in the grid.
You can view an online demo here
This is a very simple implementation however this could be extended much further as an application. Isolated Storage to store XAML, save it back to a WCF Service etc.
You could take the concept further even still and use a duplex WCF service (or sockets) to post XAML between different clients.
The key thing when dealing with dynamic XAML is using System.Windows.Markup.XamlReader.Load to load the XAML.
The code is below.
XAML
<Grid x:Name="LayoutRoot">
<Grid.ColumnDefinitions>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<Grid x:Name="gridDynamic"
Grid.Row="0"
Height="500" Width="500"/>
<StackPanel Orientation="Horizontal" Grid.Row="1">
<TextBox x:Name="myTextbox"
Text="Load Xaml"
AcceptsReturn="True" TextWrapping="Wrap"
Margin="5" Height="200" Width="500"/>
<Button Content="Load Xaml"
Height="30" Width="100"
Click="Button_Click"/>
</StackPanel>
</Grid>
C#
public partial class DynamicXaml : UserControl
{
public DynamicXaml()
{
InitializeComponent();
myTextbox.Text = @"<Grid xmlns=""http://schemas.microsoft.com/client/2007"" xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml""><Ellipse Height=""100"" Width=""100"" Fill=""Red""/></Grid>";
}
private void Button_Click(object sender, RoutedEventArgs e)
{
UIElement xamlElement = (UIElement)System.Windows.Markup.XamlReader.Load(myTextbox.Text);
gridDynamic.Children.Clear();
gridDynamic.Children.Add(xamlElement);
}
}
Sometimes it is fun to redo something you did a while back. I did a cool little application back in 1.1 days which I have decided to update to Silverlight 2.0. All it is an image with a couple of invisible buttons where the eyes are. If you click on the eyes it will play a media file.
Click on the eyes below to see it in action (switch on your speakers)
It's a fun little sample and it brings kind of interesting possibilities to Silverlight 2. This technique can be used to bring a rich image map type control to Web Pages. It can also be use to bring much richer UI's. Why not have a media player which is a photograph of your stereo?
The XAML
<Grid>
<Canvas>
<Image x:Name="myImage"
Source="/Assets/Images/WeeMee.JPG">
</Image>
<Button x:Name="leftEye"
Canvas.Left="42" Canvas.Top="49"
Height="12" Width="10"
Cursor="Hand"
Opacity="0"
Click="leftEye_Click"/>
<Button x:Name="rightEye"
Canvas.Left="57" Canvas.Top="49"
Height="12" Width="10"
Cursor="Hand"
Opacity="0"
Click="rightEye_Click"/>
</Canvas>
<!-- Media 1-->
<MediaElement x:Name="media1"
AutoPlay="False"
Source="/Assets/Audio/cutitout.wma">
</MediaElement>
<!-- Media 2-->
<MediaElement x:Name="media2"
AutoPlay="False"
Source="/Assets/Audio/laugh.wma">
</MediaElement>
</Grid>
The C#
private void leftEye_Click(object sender, RoutedEventArgs e)
{
media1.Stop();
media2.Stop();
media1.Play();
}
private void rightEye_Click(object sender, RoutedEventArgs e)
{
media1.Stop();
media2.Stop();
media2.Play();
}
I've been messing around with the Open File Dialog in Silverlight 2.0 Beta 2.
The open file dialog (OFD) is the only method that a user can access the local file system in a Silverlight Application (outside of Isolated Storage).
The cool thing about it is is that you can work with not just only text files but other types of files too.
Single or Multiple Files
The OFD supports both a single file select mode or multi file select via the (Multiselect) property.
OpenFileDialog ofd = new OpenFileDialog();
ofd.Multiselect = false;
Filtering to MP3 or WMA files
// Initialise
OpenFileDialog ofd = new OpenFileDialog();
// Filter to wma and mp3
ofd.Filter = "MP3 Files (*.mp3)|*.mp3|WMA Files (*.wma)|*.wma";
ofd.Multiselect = false;
// Show the open file dialog
ofd.ShowDialog();
Playing Local Media Files
The following bit of code will set the source of a medialement to the stream of the selected file. In this case it allow you to play a local video or audio file.
// Initialise
OpenFileDialog ofd = new OpenFileDialog();
// Filter to wma and mp3
ofd.Filter = "MP3 Files (*.mp3)|*.mp3|WMA Files (*.wma)|*.wma";
ofd.Multiselect = false;
// Show the open file dialog
ofd.ShowDialog();
// Do we have a selected file
if (ofd.SelectedFile != null)
{
// Set the source as the local file
mediaPlayer.AutoPlay = true;
mediaPlayer.SetSource(ofd.SelectedFile.OpenRead());
}
Text Files
If you wanna be a little more traditional in your use of the open file dialog, you can use OpenText() rather than OpenRead() to allow you to interact with the text file. An advantage of OpenText is that it gives you a StreamReader so you have access to ReadToEnd() etc.
private void btnOpen_Click(object sender, RoutedEventArgs e)
{
// Initialise
OpenFileDialog ofd = new OpenFileDialog();
// Filter to wma and mp3
ofd.Filter = "MP3 Files (*.mp3)|*.mp3|WMA Files (*.wma)|*.wma";
ofd.Multiselect = false;
// Show the open file dialog
ofd.ShowDialog();
// Do we have a selected file
if (ofd.SelectedFile != null)
{
string myText = ofd.SelectedFile.OpenText().ReadToEnd();
}
}
If you want to select files then you should use the SelectedFiles property rather than SelectedFile and you will be able to enumerate through all the selected files.
Uses of the Open File Dialog
In a normal web scenario using a Silverlight Control to perform uploading of files is a much richer experience than using the equivalent Html Control. You have the ability to select, process and upload multiple files at once.
The ability to perform client side validation of a file (CSV validation, XML validation) is a great feature and should encourage great take up in web scenarios.
The only thing I really want now is a Save File Dialog.
Building a little script in SQL to allow me to autogenerate mobile phone numbers.
I know I can do this with Red-Gate's Data Generator but it is nice to build the SQL yourself.
Anyways the SQL to pad the mobile phone number with zeroes is:
-- This ensures my number is 11 digits long 079 + 8 other digits (padded with zeroes at the beginning
'079' + REPLICATE('0', (8 - LEN(@number))) + @number)
Following on from my last post on "Why do normal people not use Live Search?", I think I might have found the answer. I'm not convinced "non techies" have heard of Live Search. I asked a couple of folks yesterday who don't work in IT. They have heard of Google, they have heard of Yahoo, they have never heard of Live Search.
Now I did surmise yesterday that for normal searches that Google, Yahoo and Live probably return a result set which are similar (or good enough), so these days it doesn't really matter so much which search engine you use (for normal searches). This of course was not always the case hence why most people moved to Google and stuck to it.
So If I was Microsoft how would I tackle Google? I think I might take a leaf out of Apple's book and go for the cool factor. However this requires lots of marketing, imaging and branding (probably still cheaper than buying Yahoo however).
Also I think the stuff that is really great is things like the near real time statistics as part of the results, e.g. if you search for a sports team you get the last result, next game etc. Try and save folks that extra click. I would maybe focus in on that stuff.
I would probably take a 2 prong approach try and convince Techies and Normal folks independently, as the reasons for using Google are very similar (historically) but very different (now). A cool brand is not going to convince techies that they should switch to Live for their technical searches (results matter in this case), just as much as good result sets (unless they are dramatically different i.e. basically a brand new way of doing things) are not going to convince non techies (as the results are generally good enough) so you need to give them something else. I personally think that something else is UX, Image and Brand.
One real opportunity is to make use of the work they did with Tafiti to look at different methods of search.
Silverlight provides a real opportunity to provide a UX that Google will find difficult to compete with. Isolated storage to store previous searches, different visualisations on searches, the list is endless.