Pages

Showing posts with label Silverlight. Show all posts
Showing posts with label Silverlight. Show all posts

Wednesday, 2 November 2011

Calling javascript function from silverlight


Introduction

When working with Silverlight, we are working with managed code (C#, VB). Sometimes, we need to callback to HTML page from managed code.
In this article, we walkthrough how to call managed code from JavaScript and call JavaScript function from managed code.

Background

To call JavaScript function from Silverlight, HtmlPage class of System.Windows.Browser namespace is used to allow the user to access and manipulate browser DOM (Document Object Model).
ScriptableMemberAtrribute class indicates that method or property is accessible for JavaScript caller.
To permit user to access method of Silverlight from JavaScript, you have to set [ScriptableMember] attribute to that method.

Using the Code

Let's start step by step including source to demonstrate how to communication between JavaScript and Silverlight.

First we start with Calling JavaScript function from Silverlight

Step 1: First, create one class in a Silverlight project, which describes method to call from JavaScript.

Step 2: Switch to Web project and open HTML page.

Step 3: Create Method in HTML page called from Silverlight

//.js file

function alertText(text) {

alert(text);

}
function sendText() {

return "Hi from Javascript!";

}

Step 4: In User Control, create Button to call JavaScript function.

//page.xmal


<Grid x:Name="LayoutRoot" Background="Transparent">

<Grid.RowDefinitions>

<RowDefinition Height="50"></RowDefinition>

<RowDefinition Height="50"></RowDefinition>

</Grid.RowDefinitions>

<Grid.ColumnDefinitions>

<ColumnDefinition Width="200"></ColumnDefinition>

<ColumnDefinition Width="200"></ColumnDefinition>

</Grid.ColumnDefinitions>

<Button x:Name="btnFireJavascript" Grid.Column="0" Click="btnFireJavascript_Click" Width="100" Height="30" Content="Send Data!"></Button>

<Button x:Name="btnReceiveJavascript" Click="btnReceiveJavascript_Click" Grid.Column="1" Width="100" Height="30" Content="Receive Data!"></Button>

<TextBox x:Name="txtReturnData" Height="30" Width="150" Grid.Row="1" Grid.ColumnSpan="2"></TextBox>

</Grid>

//page.xaml.cs

private void btnFireJavascript_Click(object sender, RoutedEventArgs e)
{
HtmlPage.Window.Invoke("alertText", new string[] { "Hi!" });
}
private void btnReceiveJavascript_Click(object sender, RoutedEventArgs e)
{
string obj = HtmlPage.Window.Invoke("sendText", null) as string;
txtReturnData.Text = obj;
}

By clicking on button, we need to invoke JavaScript function by using System.Windows.Browser.HtmlPage.Window.Invoke method. This method will call JavaScript "sendText" method will return the entered text disyplay the "alertText" method with "From Silverlight" as alert messagebox.In the next step, write method in HTML page of Web project has XAP file as a Object parameter.
 Step 5: Drag the reference of the js file to Web project

//silverlighttestpage.aspx drag reference

<script type="text/javascript" src="MyFunctions.js" ></script>

This is just a simple demo example, you can also use Silverlight property from JavaScript as well as JavaScript member from Silverlight.

Please put he comments.......





Wednesday, 13 April 2011

silverlight life cycle

Remember that Silverlight is running on the client, not on the server as normal ASP.NET pages.. there is no such as Page Life Cycle in Silverlight.. but there are some events that will be executed on the client side in a specific order.

1) First the App constructor in the App.xaml file.

2) The App's Applicaiton_Startup event which will be executed every time you open your Silverlight app

3) The Main page's constructor..  It will be the constructor of the page assigned to the RootVisual properly within the App's Application_Satrup event.

4) InitializeCompnent, only to make sure the components are singed to variables so you can use them. I hope this one will be removed in the future and be handled elsewhere.

5) If you have hooked up to the Loaded event within the Main Page Constructor, that event will then be executed, same with the rest event listen in the order they will be executed if you have hooked up to them.

6) Then the SizeChanged event

7)  Then the LayoutUpdated event

8) Then GotFocus if you mark the Silverlight app.

If you navigate from your Silverlight app or close the Browser the App's Application_Exit event will be executed.

As you may figure out, there is no Life Cycle.. so what you can do is to get your default data and bind it to control within the constructor or even better (regarding to me, based on what you should do), in the Loaded event.

If you have a button control on the Silverlight app and press it, there will never we a post back, back to the server. The click event will just simply be fired of on the client-side, it's where the code is executed.. To get data from a server, you can for example use a WCF service, Web Service, WebClient, .NET RIA Services etc.. they will make the call to the server from the client side for you.

Building apps with Silverlight, is more or less similar way of building a Desktop apps, for example WinForms or WPF apps, remember ASP.NET is stateless and everything is executed and handled on the server-side, Silverlight is not stateless and everything that is executed is executed by default on the client-side, only when you make call to the server, code on the server-side will be executed. So no refresh, no reloading of pages, no page life cycle, ViewState, just a beautiful rich client that holds state ;)

Here are two blog posts on my blog that can be of interest, it's regarding states and also Architecture

http://weblogs.asp.net/fredriknormen/archive/2009/08/18/different-ways-to-keep-state-when-building-ria-with-silverlight.aspx

http://weblogs.asp.net/fredriknormen/archive/2009/04/19/ria-architecture-with-silverlight-in-mind.aspx

Tuesday, 22 February 2011

grid with checkbox column in silverlight

 /////////////xaml code./////////////////////////////////
<data:DataGrid x:Name="dgPerson" Margin="8" IsReadOnly="True" 
                   LoadingRow="dgPerson_LoadingRow"  AutoGenerateColumns="False" Width="425" >
                            <data:DataGrid.Columns>
                                <data:DataGridTemplateColumn Width="80" >
                                    <data:DataGridTemplateColumn.CellTemplate>
                                        <DataTemplate>
                                            <CheckBox x:Name="chkPerson" Click="chkPerson_Click"
                                      VerticalAlignment="Center" IsChecked="false" HorizontalAlignment="Center" HorizontalContentAlignment="Center"/>
                                        </DataTemplate>
                                    </data:DataGridTemplateColumn.CellTemplate>
                                </data:DataGridTemplateColumn>
                                <data:DataGridTextColumn Header="Fee Type" Binding="{Binding Residualfee}" MinWidth="120" Width="SizeToCells" CanUserReorder="True" CanUserSort="True"/>
                                <data:DataGridTemplateColumn Width="80" Header="Fee" >
                                    <data:DataGridTemplateColumn.CellTemplate>
                                        <DataTemplate>
                                            <TextBox Width="120" Height="30" Name="feeamount"  Text="{Binding FeeAmount,Mode=TwoWay}"
                                                     ></TextBox>
                                        </DataTemplate>
                                    </data:DataGridTemplateColumn.CellTemplate>
                                </data:DataGridTemplateColumn>
                            </data:DataGrid.Columns>
                        </data:DataGrid>
                        <data:DataPager x:Name="dataPager1" Width="425" Margin="0,-10,0,0"
                                    Source="{Binding Path=ItemsSource,ElementName=dgPerson}"
                        PageSize="2"    DisplayMode="FirstLastPreviousNext" ></data:DataPager>

//////////////////////////public var////////////////////
 //List for Original List of Facilitie
        ObservableCollection<AssignFecilitieToProvision> myList;

        //List for selected Facilitie
        ObservableCollection<AssignFecilitieToProvision> personList = new ObservableCollection<AssignFecilitieToProvision>();
////////////////////////////////chk _clik////////////////////
 CheckBox chk = sender as CheckBox;

            bool check = chk.IsChecked.Value;
            var obj = dgPerson.SelectedItem as AssignFecilitieToProvision;
           
            Facilitie p = chk.DataContext as Facilitie;
            if (check)
            {
                if (!personList.Contains(obj))
                    personList.Add(obj);

            }
            else
            {
                personList.Remove(obj);
            }
////////////////save button////////////
foreach (var item in personList)
            {
///////////do insert
}

Friday, 18 February 2011

Telerik radgridview in silverlight

 xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"

<telerik:RadGridView x:Name="RadGridView1" ScrollViewer.VerticalScrollBarVisibility="Auto" ScrollViewer.HorizontalScrollBarVisibility="Auto" Loaded="RadGridView1_Loaded" AutoGenerateColumns="False" RowDetailsVisibilityMode="VisibleWhenSelected" CanUserFreezeColumns="False">
                            <telerik:RadGridView.Columns>
                                <!--<telerik:GridViewDataColumn Header="Sl No" DataMemberBinding="{Binding Slno}" />-->
                                <!--<telerik:GridViewComboBoxColumn Header="Provision Name" Width="200"
                                   DataMemberBinding="{Binding Provision, Mode=TwoWay}"
                                   UniqueName="Provision"
                                   ItemsSourceBinding="{Binding Provision}"
                                   SelectedValueMemberPath="ProvisionId"
                                                               
                                   DisplayMemberPath="Provision" x:Name="CMBProvision">
                                   
                                </telerik:GridViewComboBoxColumn>

                                <telerik:GridViewComboBoxColumn x:Name="CMBResidual" Header="ResidualFee Name" Width="200"
                                  DataMemberBinding="{Binding Residualfee, Mode=TwoWay}"
                                   UniqueName="Residualfee"
                                   ItemsSourceBinding="{Binding Residualfee}"
                                   SelectedValueMemberPath="ResidualfeeId"
                                   DisplayMemberPath="Residualfee" >

                                </telerik:GridViewComboBoxColumn>-->
                                <telerik:GridViewDataColumn Header="Provision Name" Width="200" DataMemberBinding="{Binding Provision, Mode=TwoWay}" >
                                    <telerik:GridViewDataColumn.CellTemplate>
                                        <DataTemplate>
                                            <TextBlock Text="{Binding Provision}" />
                                        </DataTemplate>
                                    </telerik:GridViewDataColumn.CellTemplate>
                                    <telerik:GridViewDataColumn.CellEditTemplate>
                                        <DataTemplate>
                                            <TextBox x:Name="TxtProvisionnames" Text="{Binding Provision}" SelectionChanged="TxtProvisionnames_SelectionChanged"></TextBox>
                                        </DataTemplate>
                                    </telerik:GridViewDataColumn.CellEditTemplate>


                                </telerik:GridViewDataColumn>


                                <telerik:GridViewDataColumn Header="ResidualFee Name" Width="200" DataMemberBinding="{Binding Residualfee, Mode=TwoWay}" >
                                    <telerik:GridViewDataColumn.CellTemplate>
                                        <DataTemplate>
                                            <TextBlock Text="{Binding Residualfee}" />
                                        </DataTemplate>
                                    </telerik:GridViewDataColumn.CellTemplate>
                                    <telerik:GridViewDataColumn.CellEditTemplate>
                                        <DataTemplate>
                                            <TextBox x:Name="TxtResidualfeenames" Text="{Binding Residualfee}" SelectionChanged="TxtResidualfeenames_SelectionChanged"></TextBox>
                                        </DataTemplate>
                                    </telerik:GridViewDataColumn.CellEditTemplate>


                                </telerik:GridViewDataColumn>
                                <!--<telerik:GridViewColumn Width="150">
                                    <telerik:GridViewColumn.CellTemplate>
                                        <DataTemplate x:Name="dtupdate">
                                          
                                            <HyperlinkButton x:Name="BtnUpdates" Content="Update" Tag="{Binding Slno}"
                                                FontWeight="Normal" Click="BtnUpdates_Click"></HyperlinkButton>
                                        </DataTemplate>
                                    </telerik:GridViewColumn.CellTemplate>
                                </telerik:GridViewColumn>-->



                                <telerik:GridViewColumn Width="150">
                                    <telerik:GridViewColumn.CellTemplate>
                                        <DataTemplate x:Name="dtDelete">
                                            <!--<telerik:RadButton Content="Update" Width="80" Height="30" Name="BtnUpdates" Click="BtnUpdates_Click"></telerik:RadButton>-->
                                            <HyperlinkButton x:Name="hypDelete" Content="Delete" Tag="{Binding Slno}"
                                                FontWeight="Normal" Click="hypDelete_Click"></HyperlinkButton>
                                        </DataTemplate>
                                    </telerik:GridViewColumn.CellTemplate>
                                </telerik:GridViewColumn>

                            </telerik:RadGridView.Columns>

                        </telerik:RadGridView>
                        <sdk:DataPager x:Name="dataPager"
                                    Source="{Binding Path=ItemsSource,ElementName=RadGridView1}"
                        PageSize="6"    DisplayMode="FirstLastPreviousNext" ></sdk:DataPager>

Wednesday, 9 February 2011

applying styles for ag menus in silverlight

    <ResourceDictionary
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:dxm="clr-namespace:DevExpress.AgMenu;assembly=DevExpress.AgMenu.v8.2"
  xmlns:dxms="clr-namespace:DevExpress.AgMenu.DefaultStyle;assembly=DevExpress.AgMenu.v8.2"
  xmlns:dxmi="clr-namespace:DevExpress.AgMenu.Internal;assembly=DevExpress.AgMenu.v8.2">

    <dxm:AgMenuTemplateList x:Key="TemplateCollection;DarkRoom">

        <dxm:AgMenuTemplateListItem Key="Horizontal">
            <dxm:AgMenuTemplateListItem.Template>
                <ControlTemplate TargetType="dxm:AgMenu">
                    <Grid>
                        <Border x:Name="ElementEmptyArea" CornerRadius="0,0,0,0">
                            <Border.Background>
                                <SolidColorBrush Color="#646874"></SolidColorBrush>
                            </Border.Background>
                        </Border>
                        <ItemsPresenter HorizontalAlignment="Left"/>
                    </Grid>
                </ControlTemplate>
            </dxm:AgMenuTemplateListItem.Template>
        </dxm:AgMenuTemplateListItem>

        <dxm:AgMenuTemplateListItem Key="Vertical">
            <dxm:AgMenuTemplateListItem.Template>
                <ControlTemplate TargetType="dxm:AgMenu">
                    <Grid>
                        <Border x:Name="ElementEmptyArea" Background="#9f0d2d" CornerRadius="0,0,0,0"/>
                        <ItemsPresenter VerticalAlignment="Top"/>
                    </Grid>
                </ControlTemplate>
            </dxm:AgMenuTemplateListItem.Template>
        </dxm:AgMenuTemplateListItem>

    </dxm:AgMenuTemplateList>

    <!-- AgMenuItem;Horizontal;ContentPresenter;DarkRoom -->
    <ControlTemplate x:Key="AgMenuItem;Horizontal;ContentPresenter;DarkRoom" TargetType="dxmi:AgMenuItemContentPresenter">
        <Grid x:Name="ElementRoot" Margin="{TemplateBinding Padding}">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="Auto"/>
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
            </Grid.RowDefinitions>
            <Grid x:Name="ElementIconCheckAreaContainer" Grid.Column="0" Grid.Row="0" VerticalAlignment="Center">
                <Grid x:Name="ElementIconCheckArea">
                    <Grid x:Name="ElementIconAreaContainer">
                        <Grid x:Name="ElementIconArea">
                            <ContentControl x:Name="ElementIcon" Content="{TemplateBinding Icon}" Margin="0,1,4,1"/>
                        </Grid>
                    </Grid>
                </Grid>
            </Grid>
            <ContentControl
          FontSize="11"
          FontFamily="Arial"
          Content="{TemplateBinding Header}"
          ContentTemplate="{TemplateBinding HeaderTemplate}"
          Grid.Column="1"
          Grid.Row="0"
          VerticalAlignment="Center"
          Foreground="{TemplateBinding Foreground}"/>
            <ContentControl
          x:Name="ElementContent"
          Content="{TemplateBinding Content}"
          ContentTemplate="{TemplateBinding ContentTemplate}"
          Foreground="{TemplateBinding Foreground}"
          Grid.Column="1"
          Grid.Row="0"/>
        </Grid>
    </ControlTemplate>

 
    <dxm:AgMenuTemplateList x:Key="ItemContainerTemplates;DarkRoom">

        <!-- Top Menu Item - Horizontal (File, Edit etc...) -->
        <dxm:AgMenuTemplateListItem Key="AgMenuItem;Horizontal">
            <dxm:AgMenuTemplateListItem.Template>
                <ControlTemplate TargetType="dxm:AgMenuItem">
                    <Grid x:Name="ElementRoot" Background="#646874">
                        <VisualStateManager.VisualStateGroups>
                            <VisualStateGroup x:Name="CommonStates">
                                <VisualState x:Name="Normal">
                                    <Storyboard>
                                        <ColorAnimation Duration="0:0:0.01" Storyboard.TargetName="ElementBackgroundGradient2" Storyboard.TargetProperty="Color" To="#646874"/>
                                        <ColorAnimation Duration="0:0:0.01" Storyboard.TargetName="ElementBackgroundGradient1" Storyboard.TargetProperty="Color" To="#646874"/>
                                        <ColorAnimation Duration="0:0:0.01" Storyboard.TargetName="ElementContentPresenter" Storyboard.TargetProperty="(Control.Foreground).(SolidColorBrush.Color)" To="White"/>
                                    </Storyboard>
                                </VisualState>
                                <VisualState x:Name="Hot">
                                    <Storyboard>
                                        <ColorAnimation Duration="0:0:0.01" Storyboard.TargetName="ElementBackgroundGradient2" Storyboard.TargetProperty="Color" To="White"/>
                                        <ColorAnimation Duration="0:0:0.01" Storyboard.TargetName="ElementBackgroundGradient1" Storyboard.TargetProperty="Color" To="White"/>
                                        <ColorAnimation Duration="0:0:0.01" Storyboard.TargetName="ElementContentPresenter" Storyboard.TargetProperty="(Control.Foreground).(SolidColorBrush.Color)" To="Black"/>
                                    </Storyboard>
                                </VisualState>
                                <VisualState x:Name="DroppedDown">
                                    <Storyboard>
                                        <ColorAnimation Duration="0:0:0.01" Storyboard.TargetName="ElementBackgroundGradient2" Storyboard.TargetProperty="Color" To="#646874"/>
                                        <ColorAnimation Duration="0:0:0.01" Storyboard.TargetName="ElementBackgroundGradient1" Storyboard.TargetProperty="Color" To="#646874"/>
                                        <ColorAnimation Duration="0:0:0.01" Storyboard.TargetName="ElementContentPresenter" Storyboard.TargetProperty="(Control.Foreground).(SolidColorBrush.Color)" To="Black"/>
                                    </Storyboard>
                                </VisualState>
                                <VisualState x:Name="DroppedDownSelected">
                                    <Storyboard>
                                        <ColorAnimation Duration="0:0:0.01" Storyboard.TargetName="ElementBackgroundGradient2" Storyboard.TargetProperty="Color" To="White"/>
                                        <ColorAnimation Duration="0:0:0.01" Storyboard.TargetName="ElementBackgroundGradient1" Storyboard.TargetProperty="Color" To="White"/>
                                        <ColorAnimation Duration="0:0:0.01" Storyboard.TargetName="ElementContentPresenter" Storyboard.TargetProperty="(Control.Foreground).(SolidColorBrush.Color)" To="Black"/>
                                    </Storyboard>
                                </VisualState>
                                <VisualState x:Name="Disabled">
                                    <Storyboard>
                                        <DoubleAnimation Duration="0:0:0.01" Storyboard.TargetName="ElementContentPresenter" Storyboard.TargetProperty="Opacity" To=".4"/>
                                    </Storyboard>
                                </VisualState>
                                <VisualState x:Name="Selected">
                                    <Storyboard>
                                        <ColorAnimation Duration="0:0:0.01" Storyboard.TargetName="ElementBackground" Storyboard.TargetProperty="Color" To="White"/>
                                        <ColorAnimation Duration="0:0:0.01" Storyboard.TargetName="ElementContentPresenter" Storyboard.TargetProperty="(Control.Foreground).(SolidColorBrush.Color)" To="Black"/>
                                    </Storyboard>
                                </VisualState>
                            </VisualStateGroup>
                        </VisualStateManager.VisualStateGroups>
                        <Border HorizontalAlignment="Stretch" Width="Auto" Grid.ColumnSpan="1"
       BorderThickness="0,0,2,0" BorderBrush="Black" >
                            <Border.Background>
                                <LinearGradientBrush EndPoint="0.5,0" StartPoint="0.5,1">
                                    <GradientStop x:Name="ElementBackgroundGradient1" Color="#FF6593CF"/>
                                    <GradientStop x:Name="ElementBackgroundGradient2" Color="#FF6593CF" Offset="1"/>
                                </LinearGradientBrush>
                            </Border.Background>
                            <Grid>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="Auto"/>
                                    <ColumnDefinition Width="*"/>
                                    <ColumnDefinition Width="Auto"/>
                                </Grid.ColumnDefinitions>
                                <dxmi:AgMenuItemContentPresenter x:Name="ElementContentPresenter"
                        Grid.Column="1"
          Foreground="LightGray"
          CheckAreaVisibility = "{TemplateBinding CheckAreaVisibility}"
          Header="{TemplateBinding Header}"
          HeaderTemplate="{TemplateBinding HeaderTemplate}"
          Icon="{TemplateBinding Icon}"
          IsRadioItem="{TemplateBinding IsRadioItem}"
          MenuOrientation="{TemplateBinding MenuOrientation}"
          Padding="7,2,4,2"
          Template="{StaticResource AgMenuItem;Horizontal;ContentPresenter;DarkRoom}"
          VerticalAlignment="Center"
          ViewStyle="{TemplateBinding ViewStyle}"
          Position="{TemplateBinding Position}"/>
                            </Grid>
                        </Border>
                    </Grid>
                </ControlTemplate>
            </dxm:AgMenuTemplateListItem.Template>
        </dxm:AgMenuTemplateListItem>

        <!-- Top Menu Item - Vertical (File, Edit etc...) -->
        <dxm:AgMenuTemplateListItem Key="AgMenuItem;Vertical">
            <dxm:AgMenuTemplateListItem.Template>
                <ControlTemplate TargetType="dxm:AgMenuItem">
                    <Grid x:Name="ElementRoot">
                        <VisualStateManager.VisualStateGroups>
                            <VisualStateGroup x:Name="CommonStates">
                                <VisualState x:Name="Normal" />
                                <VisualState x:Name="Hot">
                                    <Storyboard>
                                        <ColorAnimation Duration="0:0:0.01" Storyboard.TargetName="ElementBackgroundGradient1" Storyboard.TargetProperty="Color" To="White"/>
                                        <ColorAnimation Duration="0:0:0.01" Storyboard.TargetName="ElementBackgroundGradient2" Storyboard.TargetProperty="Color" To="White"/>
                                        <ColorAnimation Duration="0:0:0.01" Storyboard.TargetName="ElementContentPresenter" Storyboard.TargetProperty="(Control.Foreground).(SolidColorBrush.Color)" To="Black"/>
                                        <ColorAnimation Duration="0:0:0.01" Storyboard.TargetName="ElementArrowBrush" Storyboard.TargetProperty="Color" To="Black"/>
                                    </Storyboard>
                                </VisualState>
                                <VisualState x:Name="DroppedDown">
                                    <Storyboard>
                                        <ColorAnimation Duration="0:0:0.01" Storyboard.TargetName="ElementBackgroundGradient1" Storyboard.TargetProperty="Color" To="#9f0d2d"/>
                                        <ColorAnimation Duration="0:0:0.01" Storyboard.TargetName="ElementBackgroundGradient2" Storyboard.TargetProperty="Color" To="#9f0d2d"/>
                                        <ColorAnimation Duration="0:0:0.01" Storyboard.TargetName="ElementContentPresenter" Storyboard.TargetProperty="(Control.Foreground).(SolidColorBrush.Color)" To="Black"/>
                                        <ColorAnimation Duration="0:0:0.01" Storyboard.TargetName="ElementArrowBrush" Storyboard.TargetProperty="Color" To="Black"/>
                                    </Storyboard>
                                </VisualState>
                                <VisualState x:Name="DroppedDownSelected">
                                    <Storyboard>
                                        <ColorAnimation Duration="0:0:0.01" Storyboard.TargetName="ElementBackgroundGradient1" Storyboard.TargetProperty="Color" To="White"/>
                                        <ColorAnimation Duration="0:0:0.01" Storyboard.TargetName="ElementBackgroundGradient2" Storyboard.TargetProperty="Color" To="White"/>
                                        <ColorAnimation Duration="0:0:0.01" Storyboard.TargetName="ElementContentPresenter" Storyboard.TargetProperty="(Control.Foreground).(SolidColorBrush.Color)" To="Black"/>
                                        <ColorAnimation Duration="0:0:0.01" Storyboard.TargetName="ElementArrowBrush" Storyboard.TargetProperty="Color" To="Black"/>
                                    </Storyboard>
                                </VisualState>
                                <VisualState x:Name="Disabled">
                                    <Storyboard>
                                        <DoubleAnimation Duration="0:0:0.01" Storyboard.TargetName="ElementContentPresenter" Storyboard.TargetProperty="Opacity" To=".4"/>
                                    </Storyboard>
                                </VisualState>
                                <VisualState x:Name="Selected">
                                    <Storyboard>
                                        <ColorAnimation Duration="0:0:0.01" Storyboard.TargetName="ElementBackgroundGradient1" Storyboard.TargetProperty="Color" To="White"/>
                                        <ColorAnimation Duration="0:0:0.01" Storyboard.TargetName="ElementBackgroundGradient2" Storyboard.TargetProperty="Color" To="White"/>
                                        <ColorAnimation Duration="0:0:0.01" Storyboard.TargetName="ElementArrowBrush" Storyboard.TargetProperty="Color" To="White"/>
                                        <ColorAnimation Duration="0:0:0.01" Storyboard.TargetName="ElementContentPresenter" Storyboard.TargetProperty="(Control.Foreground).(SolidColorBrush.Color)" To="Black"/>
                                    </Storyboard>
                                </VisualState>
                            </VisualStateGroup>
                        </VisualStateManager.VisualStateGroups>

                        <Border HorizontalAlignment="Stretch" Grid.ColumnSpan="1" BorderThickness="0,0,2,0" BorderBrush="Black">
                            <Border.Background>
                                <LinearGradientBrush EndPoint="0.5,0" StartPoint="0.5,1">
                                    <GradientStop x:Name="ElementBackgroundGradient1" Color="#FF6593CF"/>
                                    <GradientStop x:Name="ElementBackgroundGradient2" Color="#FF6593CF" Offset="1"/>
                                </LinearGradientBrush>
                            </Border.Background>
                            <Grid>
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="Auto"/>
                                    <RowDefinition Height="*"/>
                                    <RowDefinition Height="Auto"/>
                                </Grid.RowDefinitions>
                                <Border x:Name="ElementTopBorder" Height="1" HorizontalAlignment="Stretch" Grid.Row="0" Background="#9f0d2d"/>
                                <Grid Grid.Row="1">
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="*"/>
                                        <ColumnDefinition Width="Auto"/>
                                    </Grid.ColumnDefinitions>
                                    <dxmi:AgMenuItemContentPresenter x:Name="ElementContentPresenter" Grid.Column="0"
                      Foreground="#2D2D2D"
                      CheckAreaVisibility="{TemplateBinding CheckAreaVisibility}"
      Header="{TemplateBinding Header}"
      HeaderTemplate="{TemplateBinding HeaderTemplate}"
      Icon="{TemplateBinding Icon}"
      IsRadioItem="{TemplateBinding IsRadioItem}"
      MenuOrientation="{TemplateBinding MenuOrientation}"
      Padding="11,4,24,5"
      Template="{StaticResource AgMenuItem;Vertical;ContentPresenter;DarkRoom}"
      VerticalAlignment="Top"
      ViewStyle="{TemplateBinding ViewStyle}"
      Position="{TemplateBinding Position}"/>
                                    <dxms:AgMenuSubItemArrowDefaultStyleHelper  Grid.Column="1" Margin="0,0,7,1">
                                        <dxms:AgMenuSubItemArrowDefaultStyleHelper.Background>
                                            <SolidColorBrush x:Name="ElementArrowBrush" Color="#9f0d2d"/>
                                        </dxms:AgMenuSubItemArrowDefaultStyleHelper.Background>
                                    </dxms:AgMenuSubItemArrowDefaultStyleHelper>
                                </Grid>
                                <Border Height="1" HorizontalAlignment="Stretch" Grid.Row="2" VerticalAlignment="Bottom" Background="#9f0d2d"/>
                            </Grid>
                        </Border>
                    </Grid>
                </ControlTemplate>
            </dxm:AgMenuTemplateListItem.Template>
        </dxm:AgMenuTemplateListItem>

        <!-- Sub Menu Item (File|New, File|Exit etc...) -->
        <dxm:AgMenuTemplateListItem Key="AgMenuItem;Vertical;PopupMenuItem">
            <dxm:AgMenuTemplateListItem.Template>
                <ControlTemplate TargetType="dxm:AgMenuItem">
                    <Grid x:Name="ElementRoot">
                        <VisualStateManager.VisualStateGroups>
                            <VisualStateGroup x:Name="CommonStates">
                                <VisualState x:Name="Normal"/>
                                <VisualState x:Name="Hot">
                                    <Storyboard>
                                        <ColorAnimation Duration="0:0:0.01" Storyboard.TargetName="ElementBackgroundGradient1" Storyboard.TargetProperty="Color" To="#FFBFDBFF"/>
                                        <ColorAnimation Duration="0:0:0.01" Storyboard.TargetName="ElementBackgroundGradient2" Storyboard.TargetProperty="Color" To="#FFBFDBFF"/>
                                        <ColorAnimation Duration="0:0:0.01" Storyboard.TargetName="ElementIconBackground" Storyboard.TargetProperty="Color" To="#FFBFDBFF"/>
                                    </Storyboard>
                                </VisualState>
                                <VisualState x:Name="DroppedDown"/>
                                <VisualState x:Name="DroppedDownSelected">
                                    <Storyboard>
                                        <ColorAnimation Duration="0:0:0.01" Storyboard.TargetName="ElementBackgroundGradient1" Storyboard.TargetProperty="Color" To="White"/>
                                        <ColorAnimation Duration="0:0:0.01" Storyboard.TargetName="ElementIconBackground" Storyboard.TargetProperty="Color" To="White"/>
                                        <ColorAnimation Duration="0:0:0.01" Storyboard.TargetName="ElementBackgroundGradient2" Storyboard.TargetProperty="Color" To="White"/>
                                    </Storyboard>
                                </VisualState>
                                <VisualState x:Name="Disabled">
                                    <Storyboard>
                                        <DoubleAnimation Duration="0:0:0.01" Storyboard.TargetName="ElementContentPresenter" Storyboard.TargetProperty="Opacity" To=".4"/>
                                    </Storyboard>
                                </VisualState>
                                <VisualState x:Name="Selected">
                                    <Storyboard>
                                        <ColorAnimation Duration="0:0:0.01" Storyboard.TargetName="ElementBackgroundGradient1" Storyboard.TargetProperty="Color" To="White"/>
                                        <ColorAnimation Duration="0:0:0.01" Storyboard.TargetName="ElementBackgroundGradient2" Storyboard.TargetProperty="Color" To="White"/>
                                        <ColorAnimation Duration="0:0:0.01" Storyboard.TargetName="ElementIconBackground" Storyboard.TargetProperty="Color" To="White"/>
                                    </Storyboard>
                                </VisualState>
                            </VisualStateGroup>
                        </VisualStateManager.VisualStateGroups>

                        <Border HorizontalAlignment="Left" Width="26" >
                            <Border.Background>
                                <SolidColorBrush x:Name="ElementIconBackground" Color="White"/>
                            </Border.Background>
                        </Border>

                        <Border HorizontalAlignment="Stretch" Margin="26,0,0,0"
      Width="Auto" BorderThickness="0">
                            <Border.Background>
                                <LinearGradientBrush EndPoint="0.5,0" StartPoint="0.5,1">
                                    <GradientStop x:Name="ElementBackgroundGradient1"
          Color="White"/>
                                    <GradientStop x:Name="ElementBackgroundGradient2"
          Color="White" Offset="1"/>
                                </LinearGradientBrush>
                            </Border.Background>
                        </Border>

                        <Border HorizontalAlignment="Stretch" Margin="0,0,0,0" Width="Auto" Padding="0">
                            <dxmi:AgMenuItemContentPresenter x:Name="ElementContentPresenter"
          Foreground="{TemplateBinding Foreground}"
          CheckAreaVisibility="{TemplateBinding CheckAreaVisibility}"
          Header="{TemplateBinding Header}"
          HeaderTemplate="{TemplateBinding HeaderTemplate}"
          Icon="{TemplateBinding Icon}"
          IsRadioItem="{TemplateBinding IsRadioItem}"
          Margin="4,0,30,0"
                      MinHeight="22"
                      VerticalAlignment="Center"
          MenuOrientation="{TemplateBinding MenuOrientation}"
          Template="{StaticResource AgMenuItem;Vertical;PopupMenuItemContentPresenter;DarkRoom}"
          ViewStyle="{TemplateBinding ViewStyle}"
          Position="{TemplateBinding Position}"/>
                        </Border>

                    </Grid>
                </ControlTemplate>
            </dxm:AgMenuTemplateListItem.Template>
        </dxm:AgMenuTemplateListItem>

        <!-- Sub Menu Item (File|New|Project.., File|New|Web Site etc...) -->
        <dxm:AgMenuTemplateListItem Key="AgMenuItem;Vertical;PopupMenuSubItem">
            <dxm:AgMenuTemplateListItem.Template>
                <ControlTemplate TargetType="dxm:AgMenuItem">
                    <Grid x:Name="ElementRoot">
                        <VisualStateManager.VisualStateGroups>
                            <VisualStateGroup x:Name="CommonStates">
                                <VisualState x:Name="Normal"/>
                                <VisualState x:Name="Hot">
                                    <Storyboard>
                                        <ColorAnimation Duration="0:0:0.01" Storyboard.TargetName="ElementBackgroundGradient1" Storyboard.TargetProperty="Color" To="White"/>
                                        <ColorAnimation Duration="0:0:0.01" Storyboard.TargetName="ElementBackgroundGradient2" Storyboard.TargetProperty="Color" To="White"/>
                                        <ColorAnimation Duration="0:0:0.01" Storyboard.TargetName="ElementIconBackground" Storyboard.TargetProperty="Color" To="White"/>
                                    </Storyboard>
                                </VisualState>
                                <VisualState x:Name="DroppedDown"/>
                                <VisualState x:Name="DroppedDownSelected">
                                    <Storyboard>
                                        <ColorAnimation Duration="0:0:0.01" Storyboard.TargetName="ElementBackgroundGradient1" Storyboard.TargetProperty="Color" To="White"/>
                                        <ColorAnimation Duration="0:0:0.01" Storyboard.TargetName="ElementBackgroundGradient2" Storyboard.TargetProperty="Color" To="White"/>
                                        <ColorAnimation Duration="0:0:0.01" Storyboard.TargetName="ElementIconBackground" Storyboard.TargetProperty="Color" To="White"/>
                                    </Storyboard>
                                </VisualState>
                                <VisualState x:Name="Disabled">
                                    <Storyboard>
                                        <DoubleAnimation Duration="0:0:0.01" Storyboard.TargetName="ElementContentPresenter" Storyboard.TargetProperty="Opacity" To=".4"/>
                                    </Storyboard>
                                </VisualState>
                                <VisualState x:Name="Selected">
                                    <Storyboard>
                                        <ColorAnimation Duration="0:0:0.01" Storyboard.TargetName="ElementBackgroundGradient1" Storyboard.TargetProperty="Color" To="White"/>
                                        <ColorAnimation Duration="0:0:0.01" Storyboard.TargetName="ElementBackgroundGradient2" Storyboard.TargetProperty="Color" To="White"/>
                                        <ColorAnimation Duration="0:0:0.01" Storyboard.TargetName="ElementIconBackground" Storyboard.TargetProperty="Color" To="White"/>
                                    </Storyboard>
                                </VisualState>
                            </VisualStateGroup>
                        </VisualStateManager.VisualStateGroups>

                        <Border HorizontalAlignment="Left" Width="26">
                            <Border.Background>
                                <SolidColorBrush x:Name="ElementIconBackground" Color="White"/>
                            </Border.Background>
                        </Border>
                        <Border HorizontalAlignment="Stretch" Margin="26,0,0,0" Width="Auto">
                            <Border.Background>
                                <LinearGradientBrush EndPoint="0.5,0" StartPoint="0.5,1">
                                    <GradientStop x:Name="ElementBackgroundGradient1" Color="White"/>
                                    <GradientStop x:Name="ElementBackgroundGradient2" Color="White" Offset="1"/>
                                </LinearGradientBrush>
                            </Border.Background>
                        </Border>

                        <Border HorizontalAlignment="Stretch" Margin="0,0,0,0" Width="Auto" Padding="4,2,4,2">
                            <Grid>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="*"/>
                                    <ColumnDefinition Width="Auto"/>
                                </Grid.ColumnDefinitions>
                                <dxmi:AgMenuItemContentPresenter
                        x:Name="ElementContentPresenter" Grid.Column="0"
          Foreground="{TemplateBinding Foreground}"
          CheckAreaVisibility="{TemplateBinding CheckAreaVisibility}"
          Header="{TemplateBinding Header}"
          HeaderTemplate="{TemplateBinding HeaderTemplate}"
          Icon="{TemplateBinding Icon}"
          IsRadioItem="{TemplateBinding IsRadioItem}"
          Margin="0,0,30,0"
          MenuOrientation="{TemplateBinding MenuOrientation}"
          Template="{StaticResource Vertical;PopupMenuSubItemContentPresenter;Darkroom}"
          ViewStyle="{TemplateBinding ViewStyle}"
          Position="{TemplateBinding Position}"/>
                                <!--<Path x:Name="BlackTriangle"
          Stretch="Fill" Fill="Black"
          Data="F1 M 394,286L 400,283L 400,282L 394,279L 394,286 Z " Height="7" Width="6" Grid.Column="1"/>-->
                            </Grid>
                        </Border>
                    </Grid>
                </ControlTemplate>
            </dxm:AgMenuTemplateListItem.Template>
        </dxm:AgMenuTemplateListItem>

        <dxm:AgMenuTemplateListItem Key="AgMenuSeparator;Vertical;PopupMenuItem">
            <dxm:AgMenuTemplateListItem.Template>
                <ControlTemplate TargetType="dxm:AgMenuSeparator">
                    <Grid>
                        <Border Background="#FFE9EEEE" HorizontalAlignment="Left"
                        Width="26">
                        </Border>
                        <Grid Margin="26,0,0,0">
                            <Border Height="1" Margin="8,1,8,0" Background="#FF9AC6FF" BorderThickness="0,0,0,0"/>
                        </Grid>
                    </Grid>
                </ControlTemplate>
            </dxm:AgMenuTemplateListItem.Template>
        </dxm:AgMenuTemplateListItem>
    </dxm:AgMenuTemplateList>

    <ControlTemplate TargetType="dxm:AgPopupMenu" x:Key="AgPopupMenuTemplate;DarkRoom">
        <Grid>
            <Grid Margin="0,0,0,0">
                <Border Background="Black" />
                <dxms:AgSubMenuDefaultStyleHelper Background="Black"/>
                <Border Background="Black" Margin="1,1,1,1">
                    <dxmi:AgMenuScrollViewer x:Name="ItemsPresenterContainer"
                      ScrollButtonClickMode="{TemplateBinding ScrollButtonClickMode}" Margin="0,0,0,0">
                        <ItemsPresenter/>
                    </dxmi:AgMenuScrollViewer>
                </Border>
            </Grid>
        </Grid>
    </ControlTemplate>

    <Style TargetType="dxm:AgPopupMenu" x:Key="AgPopupMenu;DarkRoom">
        <Setter Property="Template" Value="{StaticResource AgPopupMenuTemplate;DarkRoom}"/>
        <Setter Property="ItemContainerTemplates" Value="{StaticResource ItemContainerTemplates;DarkRoom}"/>
    </Style>

    <Style TargetType="dxm:AgMenu" x:Key="AgMenu;DarkRoom">
        <Setter Property="Templates" Value="{StaticResource TemplateCollection;DarkRoom}"/>
        <Setter Property="ItemContainerTemplates" Value="{StaticResource ItemContainerTemplates;DarkRoom}"/>
        <Setter Property="SubMenuStyle" Value="{StaticResource AgPopupMenu;DarkRoom}"/>
    </Style>

</ResourceDictionary>