|
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.

Leave a Reply
3902 views, 1 so far
today |
Get Updates By Email
Popular Post
- LINQ To SQL Tutorial
- LINQ To SQL Join On Multiple Conditions
- Code Sample: Programmatically Download File Using C#
- Free Icons And Images With Visual Studio 2008
- Windows 7 Control Panel In Classic Mode
- Dynamic Sort With LINQ
- Use SqlConnection With LINQ To SQL
- StyleCop Tutorial
- Write To Vista Event Log Using C#
- More Details Emerge On Microsoft Master Certification
Tag Cloud
Code Snippets
- Get Current Windows User In C#
- Get Width And Height Of Image In C#
- Get Windows Registry Size With WMI And C#
- Reverse Array Elements Using C#
- Convert Hexadecimal To Number In C#
- Get Free Disk Space Using T-SQL
- SQL Server 2008 – Get All Indexes In A Database
- Get Name Of Current Executing Assembly In C#
- Get CD Or DVD Drive Information Using WMI And C#
- Get Last Row From Table Using LINQ To SQL


July 21st, 2009 at 3:53 am
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.