稳扎稳打Silverlight(47) – 4.0UI之操作剪切板, 隐式样式, CompositeTransform, 拖放外部文件及程序中

前言

[索引页]
[源码下载]

  上同一首文章被,我们大概介绍了什么使O365遭遇SharePoint
Online文档库,SharePoint
Online的亮点就是是提供给咱们不少百般好开箱即用的力量,让我们很快的搭建站点,方便之应用和护卫我们的内容,用最为少之支出工作量完成站点建设。

稳扎稳打Silverlight(47) – 4.0UI之操作剪切板, 隐式样式,
CompositeTransform, 拖放外部文件及程序中

  本文,我们简要介绍一下SharePoint
Online中哪些转移外观,个性化站点等。

作者:webabcd

  1、大家可以看看SharePoint
Online首页的默认样式,其实过多物我们都是可以好便宜进行个性化的,包括:

介绍
Silverlight 4.0 用户界面(UI)相关:

Ø
站点图标(Part 1)

  • 操作剪切板 – 支持获取或安装剪切板中之文书信息 
  • 隐式样式(Implicit Style)
    – 将某种样式应用到某种类型的备因素,即全局样式 
  • CompositeTransform – 将余移方式共同而为同一 
  • 拖动(Drag)外部文件,并以那置于(Drop) Silverlight 程序中

Ø
左侧导航(Part 2)

在线DEMO
http://www.cnblogs.com/webabcd/archive/2010/08/09/1795417.html

Ø
顶部导航(Part 3)

示例
1、演示如何操作剪切板
Clipboard.xaml

Ø
页面名称(Part 4)

葡京在线开户 1葡京在线开户 2代码

Ø 站点外观

<navigation:Page x:Class=”Silverlight40.UI.Clipboard” 
           xmlns=”http://schemas.microsoft.com/winfx/2006/xaml/presentation” 
           xmlns:x=”http://schemas.microsoft.com/winfx/2006/xaml” 
           xmlns:d=”http://schemas.microsoft.com/expression/blend/2008″
           xmlns:mc=”http://schemas.openxmlformats.org/markup-compatibility/2006″
           xmlns:navigation=”clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation”
           Title=”Clipboard Page”>
    <Grid x:Name=”LayoutRoot”>
        <StackPanel HorizontalAlignment=”Left”>
            
            <TextBox Name=”txtMsg” Width=”200″ Height=”50″ Margin=”5″ />

葡京在线开户 3

            <!– 复制 txtMsg 中之公文 –>
            <Button Name=”btnCopy” Content=”复制” Margin=”5″ Click=”btnCopy_Click” />

  2、点击右侧上比赛小齿轮展开菜单,点击“网站设置”进入站点设置页面;

            <!– 将推切板中之文件粘贴到 txtMsg –>
            <Button Name=”btnPaste” Content=”粘贴” Margin=”5″ Click=”btnPaste_Click” />

葡京在线开户 4

        </StackPanel>
    </Grid>
</navigation:Page>

  3、默认包括站点标题、站点说明、站点图标说明,我们得以页面及利于的修改站点的如下属性;

Clipboard.xaml.cs

葡京在线开户 5

葡京在线开户 6葡京在线开户 7代码

  4、我们输入了属性,然后点击右侧下角的确定按钮保存属性;

/*
 * Silverlight 4.0 支持对剪切板的访,只支持获取或安装剪切板中之公文信息
 *     System.Windows.Clipboard.SetText(string s) – 将点名的字符串复制到剪切板
 *     System.Windows.Clipboard.GetText() – 获取剪切板中之公文信息
 *     
 * 只有在 Click 或 KeyDown 事件的处理程序中才好看剪切板
 * 访问剪切板时,Silverlight 会弹出对话框要求用户展开确认,如果用户禁止了,则会掀起那个。如果程序是“被信任的应用程序”则未见面弹有该对话框
 */

葡京在线开户 8

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;
using System.Windows.Navigation;

  5、然后我们看一下SharePoint
Online中之导航设置,同样是在网站设置中;我们率先看一下导航元素是设置,如下图:

namespace Silverlight40.UI
{
    public partial class Clipboard : Page
    {
        public Clipboard()
        {
            InitializeComponent();
        }

葡京在线开户 9

        protected override void OnNavigatedTo(NavigationEventArgs e)
        {

  6、我们得因需要启用快速启动或树视图,两者的现实分可以参照描述;我了解快速启动就是左导航,树视图就是网站组织;

        }

葡京在线开户 10

        private void btnCopy_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                System.Windows.Clipboard.SetText(txtMsg.Text);
            }
            catch (System.Security.SecurityException ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

  7、然后进网站设置 –
导航;通常咱们无起头启树视图,这个是力不从心设置的;而高速启动为即是左导航,是得在导航里增删改查的;

        private void btnPaste_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                txtMsg.SelectedText = System.Windows.Clipboard.GetText();
            }
            catch (System.Security.SecurityException ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
    }
}

葡京在线开户 11

2、演示 Silverlight 4.0 对隐式样式(全局样式)的支撑
ImplicitStyle.xaml

  8、可以望导航包括全局导航与当下导航,我们一般选择结构导航,至于托管导航,我们会以未来底文章被负有介绍;

葡京在线开户 12葡京在线开户 13代码

  导航的安可以包该站点的子站点或者页面,我们可勾选是否连;

<navigation:Page x:Class=”Silverlight40.UI.ImplicitStyle” 
           xmlns=”http://schemas.microsoft.com/winfx/2006/xaml/presentation” 
           xmlns:x=”http://schemas.microsoft.com/winfx/2006/xaml” 
           xmlns:d=”http://schemas.microsoft.com/expression/blend/2008″
           xmlns:mc=”http://schemas.openxmlformats.org/markup-compatibility/2006″
           xmlns:navigation=”clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation”
           Title=”ImplicitStyle Page”>
    <Grid x:Name=”LayoutRoot”>

葡京在线开户 14

        <!–
            隐式样式(Implicit Style) – 将某种样式应用到某种类型的兼具因素,即全局样式
        –>
        <ToggleButton Width=”200″ Height=”50″ Content=”用于演示隐式样式(Implicit Style)。ToggleButton 的体设置详细 Assets/ToggleButtonStyle.xaml” />
        
    </Grid>
</navigation:Page>

  9、我们好方便的装导航排序和丰富改导航;

App.xaml

葡京在线开户 15

葡京在线开户 16葡京在线开户 17代码

  10、导航链接除了主导的题、链接、说明性,还有一个异常实惠的性质叫做访问群体,我们可以以走访群体里上加全局看群体、AD通讯组或者安全组、SharePoint用户组来限制用户是否足以看来该链接;

<Application   
  x:Class=”Silverlight40.App”
  xmlns=”http://schemas.microsoft.com/winfx/2006/xaml/presentation”
  xmlns:x=”http://schemas.microsoft.com/winfx/2006/xaml"&gt;

葡京在线开户 18

    <Application.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source=”Assets/ToggleButtonStyle.xaml”/>
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Application.Resources>

  11、选择访问群体,可以由此寻找的方法进行搜索;

</Application>

葡京在线开户 19

ToggleButtonStyle.xaml

  12、添加了的组织导航,如下图:

葡京在线开户 20葡京在线开户 21代码

葡京在线开户 22

<ResourceDictionary
  xmlns=”http://schemas.microsoft.com/winfx/2006/xaml/presentation” 
  xmlns:x=”http://schemas.microsoft.com/winfx/2006/xaml”
  xmlns:navigation=”clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation”>

  13、回到我们站点的首页,可以看出站点图标、左侧导航、顶部导航还已经修改了,而且,我们啊克见到步骤10挨补充加标题和上加链接的别;

    <!– ToggleButton 的隐式样式(Implicit Style) –>
    <Style TargetType=”ToggleButton”>
        <Setter Property=”Background” Value=”#FF1F3B53″/>
        <Setter Property=”Foreground” Value=”#FF000000″/>
        <Setter Property=”Padding” Value=”3″/>
        <Setter Property=”BorderThickness” Value=”1″/>
        <Setter Property=”BorderBrush”>
            <Setter.Value>
                <LinearGradientBrush EndPoint=”0.5,1″ StartPoint=”0.5,0″>
                    <GradientStop Color=”#FFA3AEB9″ Offset=”0″/>
                    <GradientStop Color=”#FF8399A9″ Offset=”0.375″/>
                    <GradientStop Color=”#FF718597″ Offset=”0.375″/>
                    <GradientStop Color=”#FF617584″ Offset=”1″/>
                </LinearGradientBrush>
            </Setter.Value>
        </Setter>
        <Setter Property=”Template”>
            <Setter.Value>
                <ControlTemplate TargetType=”ToggleButton”>
                    <Grid>
                        <VisualStateManager.VisualStateGroups>
                            <VisualStateGroup x:Name=”CommonStates”>
                                <VisualState x:Name=”Normal”/>
                                <VisualState x:Name=”MouseOver”>
                                    <Storyboard>
                                        <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty=”(UIElement.Opacity)” Storyboard.TargetName=”Background”>
                                            <EasingDoubleKeyFrame KeyTime=”0″ Value=”1″/>
                                        </DoubleAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>
                                <VisualState x:Name=”Pressed”>
                                    <Storyboard>
                                        <ColorAnimationUsingKeyFrames Storyboard.TargetProperty=”(Border.Background).(SolidColorBrush.Color)” Storyboard.TargetName=”Background”>
                                            <SplineColorKeyFrame KeyTime=”0″ Value=”#FFffe575″/>
                                        </ColorAnimationUsingKeyFrames>
                                        <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty=”(UIElement.Opacity)” Storyboard.TargetName=”Background”>
                                            <EasingDoubleKeyFrame KeyTime=”0″ Value=”1″/>
                                        </DoubleAnimationUsingKeyFrames>
                                        <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty=”(UIElement.Opacity)” Storyboard.TargetName=”grid”>
                                            <EasingDoubleKeyFrame KeyTime=”0″ Value=”0″/>
                                        </DoubleAnimationUsingKeyFrames>
                                        <ColorAnimationUsingKeyFrames Storyboard.TargetProperty=”(Border.BorderBrush).(SolidColorBrush.Color)” Storyboard.TargetName=”Background”>
                                            <EasingColorKeyFrame KeyTime=”0″ Value=”#FFC28A30″/>
                                        </ColorAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>
                                <VisualState x:Name=”Disabled”>
                                    <Storyboard>
                                        <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty=”Opacity” Storyboard.TargetName=”DisabledVisualElement”>
                                            <SplineDoubleKeyFrame KeyTime=”0″ Value=”.55″/>
                                        </DoubleAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>
                            </VisualStateGroup>
                            <VisualStateGroup x:Name=”CheckStates”>
                                <VisualState x:Name=”Checked”>
                                    <Storyboard>
                                        <ColorAnimationUsingKeyFrames Storyboard.TargetProperty=”(Border.Background).(SolidColorBrush.Color)” Storyboard.TargetName=”Background2″>
                                            <SplineColorKeyFrame KeyTime=”0″ Value=”#FFffe575″/>
                                        </ColorAnimationUsingKeyFrames>
                                        <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty=”(UIElement.Opacity)” Storyboard.TargetName=”Background2″>
                                            <EasingDoubleKeyFrame KeyTime=”0″ Value=”1″/>
                                        </DoubleAnimationUsingKeyFrames>
                                        <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty=”(UIElement.Opacity)” Storyboard.TargetName=”grid2″>
                                            <EasingDoubleKeyFrame KeyTime=”0″ Value=”0″/>
                                        </DoubleAnimationUsingKeyFrames>
                                        <ColorAnimationUsingKeyFrames Storyboard.TargetProperty=”(Border.BorderBrush).(SolidColorBrush.Color)” Storyboard.TargetName=”Background2″>
                                            <EasingColorKeyFrame KeyTime=”0″ Value=”#FFC28A30″/>
                                        </ColorAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>
                                <VisualState x:Name=”Unchecked”/>
                            </VisualStateGroup>
                            <VisualStateGroup x:Name=”FocusStates”>
                                <VisualState x:Name=”Focused”>
                                </VisualState>
                                <VisualState x:Name=”Unfocused”/>
                            </VisualStateGroup>
                        </VisualStateManager.VisualStateGroups>
                        <Border x:Name=”Background” BorderThickness=”{TemplateBinding BorderThickness}” Background=”#FFFDF7E2″ CornerRadius=”3″ BorderBrush=”#FFF0C958″ Opacity=”0″>
                            <Grid x:Name=”grid” Margin=”1″>
                                <Grid.Background>
                                    <LinearGradientBrush EndPoint=”0.5,1″ StartPoint=”0.5,0″>
                                        <GradientStop Color=”#FFFDF7E2″ Offset=”1″/>
                                        <GradientStop Color=”#FFFCEDB3″/>
                                    </LinearGradientBrush>
                                </Grid.Background>
                            </Grid>
                        </Border>
                        <Border x:Name=”Background2″ BorderThickness=”{TemplateBinding BorderThickness}” Background=”#FFFDF7E2″ CornerRadius=”3″ BorderBrush=”#FFF0C958″ Opacity=”0″>
                            <Grid x:Name=”grid2″ Margin=”1″>
                                <Grid.Background>
                                    <LinearGradientBrush EndPoint=”0.5,1″ StartPoint=”0.5,0″>
                                        <GradientStop Color=”#FFFDF7E2″ Offset=”1″/>
                                        <GradientStop Color=”#FFFCEDB3″/>
                                    </LinearGradientBrush>
                                </Grid.Background>
                            </Grid>
                        </Border>
                        <ContentPresenter x:Name=”contentPresenter” ContentTemplate=”{TemplateBinding ContentTemplate}” Content=”{TemplateBinding Content}” HorizontalAlignment=”{TemplateBinding HorizontalContentAlignment}” Margin=”{TemplateBinding Padding}” VerticalAlignment=”{TemplateBinding VerticalContentAlignment}”/>
                        <Rectangle x:Name=”DisabledVisualElement” Fill=”#FFFFFFFF” IsHitTestVisible=”false” Opacity=”0″ RadiusY=”3″ RadiusX=”3″/>
                        <Rectangle x:Name=”FocusVisualElement” IsHitTestVisible=”false” Margin=”1″ Opacity=”0″ RadiusY=”2″ RadiusX=”2″ Stroke=”#FF6DBDD1″ StrokeThickness=”1″/>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
    
</ResourceDictionary>

葡京在线开户 23

3、演示 CompositeTransform 的效果
CompositeTransform.xaml

  14、下面,我们尝试修改一下网站的外观,同样是当网站设置,找到外观 –
更改外观;

葡京在线开户 24葡京在线开户 25代码

葡京在线开户 26

<navigation:Page x:Class=”Silverlight40.UI.CompositeTransform” 
           xmlns=”http://schemas.microsoft.com/winfx/2006/xaml/presentation” 
           xmlns:x=”http://schemas.microsoft.com/winfx/2006/xaml” 
           xmlns:d=”http://schemas.microsoft.com/expression/blend/2008″
           xmlns:mc=”http://schemas.openxmlformats.org/markup-compatibility/2006″
           xmlns:navigation=”clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation”
           Title=”CompositeTransform Page”>
    <Grid x:Name=”LayoutRoot”>
        <StackPanel HorizontalAlignment=”Left” Margin=”100,0,0,0″>
            
            <!–
                CompositeTransform – 将余变换方式同而为同一
                    CenterX – 转换中心点的 X 坐标
                    CenterY – 转换中心点的 Y 坐标
                    Rotation – 顺时针旋转角度
                    ScaleX – 沿 X 轴方向达成的缩放比例
                    ScaleY – 沿 Y 轴方向及的缩放比例
                    SkewX – X 轴扭曲角度
                    SkewY – Y 轴扭曲角度
                    TranslateX – 沿 X 轴方向及之移位距离
                    TranslateY – 沿 Y 轴方向上之运动距离
            –>
            <Rectangle Height=”100″ Width=”100″ Fill=”Red”>
                <Rectangle.RenderTransform>
                    <CompositeTransform SkewX=”30″ Rotation=”60″ ScaleX=”0.6″ ScaleY=”0.3″ />
                </Rectangle.RenderTransform>
            </Rectangle>

  15、选择一个君嗜的,点击图片即可;

            <!– 用 TransformGroup 的方上地方的 CompositeTransform 的一模一样功能 –>
            <Rectangle Height=”100″ Width=”100″ Fill=”Red”>
                <Rectangle.RenderTransform>
                    <TransformGroup>
                        <ScaleTransform ScaleX=”0.6″ ScaleY=”0.3″ />
                        <SkewTransform AngleX=”30″ />
                        <RotateTransform Angle=”60″ />
                    </TransformGroup>
                </Rectangle.RenderTransform>
            </Rectangle>

葡京在线开户 27

        </StackPanel>
    </Grid>
</navigation:Page>

  16、可以点击试用,当然也堪修改颜色、字体、网站布局等;

4、演示如何 Drag&Drop 外部文件及 Silverlight 程序中
DragAndDrop.xaml

葡京在线开户 28

葡京在线开户 29葡京在线开户 30代码

  17、试用效果使下图,如果认为对,可以点击保存,否则不太好即可;

<navigation:Page x:Class=”Silverlight40.UI.DragAndDrop” 
           xmlns=”http://schemas.microsoft.com/winfx/2006/xaml/presentation” 
           xmlns:x=”http://schemas.microsoft.com/winfx/2006/xaml” 
           xmlns:d=”http://schemas.microsoft.com/expression/blend/2008″
           xmlns:mc=”http://schemas.openxmlformats.org/markup-compatibility/2006″
           xmlns:navigation=”clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation”
           Title=”DragAndDrop Page”>
    <Grid x:Name=”LayoutRoot”>
        <StackPanel HorizontalAlignment=”Left”>

  我立马蓝色背景的Logo真是不调和,真该改完外观还变动Logo的,^_^;

            <!– 对 Silverlight 中之 UIElement 进行拖动的 Demo 详见此 –>
            <HyperlinkButton NavigateUri=”http://www.cnblogs.com/webabcd/archive/2008/11/13/1332450.html” TargetName=”_blank” Content=”在 Silverlight 中拖放 UIElement 的 Demo” />

葡京在线开户 31

            <!– 这是 DropTarget –>
            <ListBox Name=”listBox” Background=”LightBlue” Height=”400″>
                <ListBoxItem Content=”拖动外部文件及此,以查看演示效果” />
            </ListBox>

  18、再修改一不成Logo,看看我们透过一些略个性化后的站点,是休是发出一点点内网的意思了也?!O(∩_∩)O~

        </StackPanel>
    </Grid>
</navigation:Page>

葡京在线开户 32

DragAndDrop.xaml.cs

总结

葡京在线开户 33葡京在线开户 34代码

  Sharepoint
Online的有接触在快速,而且数量未会见丢掉,不需要保障服务器;当然sharepoint只是O365底一个多少有,结合Exchange
Online发送邮件,Lync Online在线聊天或很不错的。

/*
 * 拖放操作的 Demo – Silverlight 4.0 支持拖动外部文件及 Silverlight 程序中(支持多文件拖放,但是未支持文件夹拖放)
 * 
 * UIElement.AllowDrop – 指定 UIElement 是否足以据此作于 DropTarget(拖放操作的拓宽目标)。默认值为 false
 * UIElement.DragEnter – 拖动外部文件上到 UIElement 时所点的风波(事件参数类型也:DragEventArgs)
 * UIElement.DragLeave – 拖动外部文件去 UIElement 时所接触的轩然大波(事件参数类型为:DragEventArgs)
 * UIElement.DragOver – 拖动外部文件在 UIElement 中走时所接触的轩然大波(事件参数类型也:DragEventArgs)
 * UIElement.Drop – 拖动外部文件于 UIElement 中加大时所点的波(事件参数类型也:DragEventArgs)
 * DragEventArgs – 拖放操作所点的拖放事件的风波参数
 *     DragEventArgs.Data – 获取和拖放事件相关联的数码(IDataObject 类型)
 * IDataObject.GetData(DataFormats.FileDrop) – 返回给拖放的外部文件之 FileInfo 数组
 */

  同时,我们以网站设置用或会见看不到“导航”、“外观”等选,记得开启网站集功能的“SharePoint
Server 发布基础架构”和网站功能的“SharePoint Server 发布”。

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;
using System.Windows.Navigation;

using System.IO;
using System.Windows.Markup;
using System.Windows.Media.Imaging;

namespace Silverlight40.UI
{
    public partial class DragAndDrop : Page
    {
        public DragAndDrop()
        {
            InitializeComponent();
        }

        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            listBox.AllowDrop = true;

            listBox.DragEnter += new DragEventHandler(listBox_DragEnter);
            listBox.DragLeave += new DragEventHandler(listBox_DragLeave);
            listBox.DragOver += new DragEventHandler(listBox_DragOver);
            listBox.Drop += new DragEventHandler(listBox_Drop);
        }

        void listBox_DragEnter(object sender, DragEventArgs e)
        {
            listBox.Items.Add(“DragEnter”);
        }

        void listBox_DragLeave(object sender, DragEventArgs e)
        {
            listBox.Items.Add(“DragLeave”);
        }

        void listBox_DragOver(object sender, DragEventArgs e)
        {
            // listBox.Items.Add(“DragOver”);
        }

        void listBox_Drop(object sender, DragEventArgs e)
        {
            listBox.Items.Add(“Drop”);

            if (e.Data == null)
                return;

            IDataObject dataObject = e.Data as IDataObject;
            FileInfo[] files = dataObject.GetData(DataFormats.FileDrop) as FileInfo[];

            foreach (FileInfo file in files)
            {
                if (file.Exists)
                    listBox.Items.Add(“FileName: ” + file.Name + ” [FileSize: ” + file.Length + “]”);
                else
                    listBox.Items.Add(“文件无效”);
            }
        }
    }
}

OK
[源码下载]