European Silverlight Hosting BLOG

BLOG about Latest Silverlight Hosting and Its Techologies - Dedicated to European Windows Hosting Customer

Silverlight 6 Hosting - HostForLIFE.eu :: How to Create Pop Up Notifications

clock October 15, 2015 17:11 by author Rebecca

In this post, I will tell you how to create pop up notification in Silverlight. I will separate the kinds of notification into: Alert, Prompt and Confirm popup box.

There is a class called System.Windows.Browsers that comes with Silverlight. Also, there are lots of methods to create alert, prompt and confirm box using JavaScript. Let’s look further into each notification one by one:

1. Alert

HtmlPage.Window.Alert("Alert from Silverlight screen");

Same thing can be achieved using the Silverlight MessageBox. The only difference is that in case of MessageBox, you don't have the alert symbol. But at the same time with MessageBox you have the option to display appropriate title for the pop up.

MessageBox.Show("MessageBox for Silverlight", "AlertMessageBox", MessageBoxButton.OK)

2. Confirm

HtmlPage.Window.Confirm("Do you know how to call Alert from Silverlight");

The confirm method returns bool value, this can be used to perfrom further action depending upon if user clicks OK or Cancel button. Below code display how to handle the same.

bool isConfirmed = HtmlPage.Window.Confirm("Do you know how to call Alert from Silverlight");

if (isConfirmed)

 {

   //Perform some action;

 }
This thing can also be achieved using the Silverlight MessageBox. The only difference is that in case of MessageBox return type is not bool but Enum of type MessageBoxResult. Also the 3rd parameter which is of enum type MessageBoxButton should be MessageBoxButton.OkCancel

MessageBox.Show("MessageBox for Silverlight", "AlertMessageBox", MessageBoxButton.OKCancel);

MessageBoxResult isConfirmed = MessageBox.Show("MessageBox for Silverlight", "Alert MessageBox", MessageBoxButton.OKCancel);

if (isConfirmed == MessageBoxResult.OK)

 {

   //Perfrom some Action;

 }

3. Prompt

HtmlPage.Window.Prompt("whatis name of site?");

Prompt method returns string method. The input provided can be used to perform further action

string inputValue = HtmlPage.Window.Prompt("what is name of site?");

if (inputValue.Trim() == "Experts Comment")

 {

   //Perfrom some action;

 }


HostForLIFE.eu Silverlight 6 Hosting

HostForLIFE.eu is European Windows Hosting Provider which focuses on Windows Platform only. We deliver on-demand hosting solutions including Shared hosting, Reseller Hosting, Cloud Hosting, Dedicated Servers, and IT as a Service for companies of all sizes. We have customers from around the globe, spread across every continent. We serve the hosting needs of the business and professional, government and nonprofit, entertainment and personal use market segments.



Silverlight 6 Hosting - HostForLIFE.eu :: How to Create a Similar List like Mac using Silverlight

clock October 8, 2015 13:09 by author Rebecca

In this tutorial, we will create the standard Silverlight ListBox will be customized to be functionally similar to a ListBox you would find on a Mac.

The XAML for this tutorial contains a custom style that we use to disable the scrollbar:

<UserControl x:Class="CustomListBox.Page"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Width="400" Height="300">
    <Grid x:Name="LayoutRoot" Background="White">
        <Grid.Resources>
            <Style x:Key="ListBoxStyle1" TargetType="ListBox">
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="ListBox">
                            <Grid x:Name="LayoutRoot">
                                <Border Padding="5" BorderBrush="#000000" BorderThickness="1" Background="#ffffff" CornerRadius="0">
                                    <ScrollViewer x:Name="ScrollViewer" VerticalScrollBarVisibility="Hidden" Padding="{TemplateBinding Padding}" Background="{TemplateBinding Background}" BorderBrush="Transparent" BorderThickness="0">
                                        <ItemsPresenter />
                                    </ScrollViewer>
                                </Border>
                            </Grid>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
        </Grid.Resources>
        <StackPanel Margin="4" HorizontalAlignment="Left">
            <RepeatButton Width="200" Height="22" Click="Up_Click">
                <Polygon Points="5,0 10,10 0,10 5,0" Fill="#222222" />
            </RepeatButton>
            <ListBox x:Name="listbox" Width="200" Height="150" Style="{StaticResource ListBoxStyle1}">
                <ListBoxItem Content="Item 1" />
                <ListBoxItem Content="Item 2" />
                <ListBoxItem Content="Item 3" />
                <ListBoxItem Content="Item 4" />
                <ListBoxItem Content="Item 5" />
                <ListBoxItem Content="Item 6" />
                <ListBoxItem Content="Item 7" />
                <ListBoxItem Content="Item 8" />
                <ListBoxItem Content="Item 9" />
                <ListBoxItem Content="Item 10" />
                <ListBoxItem Content="Item 11" />
                <ListBoxItem Content="Item 12" />
            </ListBox>
            <RepeatButton Width="200" Height="22" Click="Down_Click">
                <Polygon Points="5,10 10,0 0,0 5,10" Fill="#222222" />
            </RepeatButton>
        </StackPanel>
    </Grid>
</UserControl>

In XAML, just apply the custom style and populate it with some test data.  There are also two repeat buttons, an up and down that will handle the scrolling for us:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace CustomListBox
{
    public partial class Page : UserControl
    {
        public Page()
        {
            InitializeComponent();
        }

        private void Up_Click(object sender, RoutedEventArgs e)
        {
            if (listbox.Items.Count > 0)
            {
                int newIndex = listbox.SelectedIndex - 1;

                if (newIndex < 0)
                {
                    newIndex = 0;
                }
                listbox.SelectedIndex = newIndex;
            }
        }

        private void Down_Click(object sender, RoutedEventArgs e)
        {
            if (listbox.Items.Count > 1)
            {
                int newIndex = listbox.SelectedIndex + 1;

                if (newIndex >= listbox.Items.Count)
                {
                    newIndex = listbox.Items.Count - 1;
                }
                listbox.SelectedIndex = newIndex;
            }
        }
    }
}

And now we're done!

HostForLIFE.eu Silverlight 6 Hosting
HostForLIFE.eu is European Windows Hosting Provider which focuses on Windows Platform only. We deliver on-demand hosting solutions including Shared hosting, Reseller Hosting, Cloud Hosting, Dedicated Servers, and IT as a Service for companies of all sizes. We have customers from around the globe, spread across every continent. We serve the hosting needs of the business and professional, government and nonprofit, entertainment and personal use market segments.



About HostForLIFE

HostForLIFE is European Windows Hosting Provider which focuses on Windows Platform only. We deliver on-demand hosting solutions including Shared hosting, Reseller Hosting, Cloud Hosting, Dedicated Servers, and IT as a Service for companies of all sizes.

We have offered the latest Windows 2019 Hosting, ASP.NET 5 Hosting, ASP.NET MVC 6 Hosting and SQL 2019 Hosting.


Tag cloud

Sign in