Get Browser Information In Silverlight
While writing Silverlight you may come across a need to get information about host browsers within your application. In Silverlight this information is exposed by BrowserInformation class within System.Windows.Browser namespace. BrowserInformation can be accessed through HtmlPage class which also lives in System.Windows.Browser namespace. Here is an example where I am retrieving information about the browser.
<StackPanel x:Name="LayoutRoot" Margin="10" Background="PaleGoldenrod"> <StackPanel.Resources> <Style x:Key="TextBlockStyle" TargetType="TextBlock"> <Setter Property="FontSize" Value="14" /> </Style> </StackPanel.Resources> <TextBlock Text="Information about your browser" HorizontalAlignment="Center" Style="{StaticResource TextBlockStyle}" /> <controls:WrapPanel> <TextBlock Text="You are using " Style="{StaticResource TextBlockStyle}"/> <TextBlock Text="{Binding Name}" Style="{StaticResource TextBlockStyle}" /> <TextBlock Text=". Version " Style="{StaticResource TextBlockStyle}" /> <TextBlock Text="{Binding BrowserVersion}" Style="{StaticResource TextBlockStyle}" /> <TextBlock Text="Your platform is " Style="{StaticResource TextBlockStyle}"/> <TextBlock Text="{Binding Platform}" Style="{StaticResource TextBlockStyle}"/> </controls:WrapPanel> </StackPanel>
We also need to assign a DataContext for our StackPanel to BrowserInformation object.
LayoutRoot.DataContext =
System.Windows.Browser.HtmlPage.BrowserInformation;
And the output on my machine is.

One Response to Get Browser Information In Silverlight
Leave a Reply Cancel reply
Top Posts
- LINQ To SQL Tutorial
- LINQ To SQL Join On Multiple Conditions
- Code Sample: Programmatically Download File Using C#
- Windows 7 Control Panel In Classic Mode
- More Details Emerge On Microsoft Master Certification
- Use SqlConnection With LINQ To SQL
- Free Icons And Images With Visual Studio 2008
- Capture XML In WCF Service
- Dynamic Sort With LINQ
- StyleCop Tutorial
Tags
.Net 2010 ADO.NET ASP.NET Azure Blogging Books Browsers C# Certification Cloud Computing Code Snippets Community Data Services Eclipse Entity Framework Google IDE Java LINQ Mac Microsoft Museum NetBeans Office Oracle REST SharePoint Silverlight SQL Server T-SQL Tips Tools Training Visual Studio Visual Studio 2010 WCF Web Windows Windows 7 Windows Forms Windows Live WMI WPF XAML


HtmlPage.BrowserInformation does not work as expected.
For FireFox and Chrome : HtmlPage.BrowserInformation.Name returns “netscape”
On IE 8 : HtmlPage.BrowserInformation.BrowserVersion returns 4.0
This is not what i want.
I need to know actual name and version of the browser on which my SL app is running.