稳扎稳打Silverlight(46) - 4.0UI之FlowDirection, TextTrimming, 响应鼠标滚轮事件, 响应鼠标右键事件, 全屏的新特性

稳扎稳打Silverlight(46) - 4.0UI之FlowDirection, TextTrimming, 响应鼠标滚轮事件, 响应鼠标右键事件, 全屏的新特性,第1张

概述[源码下载] 稳扎稳打Silverlight(46) - 4.0UI之FlowDirection, TextTrimming, 响应鼠标滚轮事件, 响应鼠标右键事件, 全屏的新特性 作者: webabcd 介绍 Silverlight 4.0 用户界面(UI)相关: FlowDirection - 指定文本或界面元素在它们的父元素中的流动方向  TextTrimming - 文字溢出时的显示方式  [源码下载]


稳扎稳打Silverlight(46) - 4.0UI之FlowDirection,TextTrimming,响应鼠标滚轮事件,响应鼠标右键事件,全屏的新特性

作者: webabcd


介绍
Silverlight 4.0 用户界面(UI)相关:
FlowDirection - 指定文本或界面元素在它们的父元素中的流动方向  TextTrimming - 文字溢出时的显示方式  响应鼠标的滚轮事件 响应鼠标的右键事件 全屏的新特性 - 当其他程序获得焦点时,是否退出全屏模式

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


示例
1、演示 FlowDirection 的效果
FlowDirectionDemo.xaml

代码 < navigation:Page  x:Class ="Silverlight40.UI.FlowDirectionDemo"  
           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
="FlowDirectionDemo Page" >
    
< StackPanel  WIDth ="200"  HorizontalAlignment ="left" >
        
        
<!--
            FrameworkElement.FlowDirection - 指定文本或界面元素在它们的父元素中的流动方向 [System.windows.FlowDirection 枚举]
                FlowDirection.leftToRight - 内容从左到右流动(默认值)
                FlowDirection.RightToleft - 内容从右到左流动
        
-->
        
        
< StackPanel  OrIEntation ="Horizontal"  FlowDirection ="RightToleft" >
            
< TextBlock  Text ="1"   />
            
< TextBlock  Text ="2"   />
            
< TextBlock  Text ="3"   />
        
</ StackPanel >

    
</ StackPanel >
</ navigation:Page >


2、演示 TextTrimming 的效果
TextTrimming.xaml

代码 < navigation:Page  x:Class ="Silverlight40.UI.TextTrimming"  
           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
="TextTrimming Page" >
    
< GrID  x:name ="LayoutRoot" >
        
< StackPanel  HorizontalAlignment ="left" >
            
            
<!--
                TextBlock.TextTrimming - 文字溢出时的显示方式 [System.windows.TextTrimming 枚举]
                    TextTrimming.None - 不做任何处理
                    TextTrimming.WordEllipsis - 在边界处,用省略号代替剩余文本
            
-->

            
< TextBlock  Text ="abcdefghijklmnopqrstuvwxyz"  tooltipService.tooltip ="abcdefghijklmnopqrstuvwxyz"  WIDth ="100"  TextTrimming ="None"   />
            
            
< TextBlock  Text ="abcdefghijklmnopqrstuvwxyz"  tooltipService.tooltip ="abcdefghijklmnopqrstuvwxyz"  WIDth ="100"  TextTrimming ="WordEllipsis"   />

        
</ StackPanel >
    
</ GrID >
</ navigation:Page >


3、演示如何响应鼠标滚轮事件
MouseWheel.xaml

代码 < navigation:Page  x:Class ="Silverlight40.UI.MouseWheel"  
           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"
           xmlns:sdk
="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"
           Title
="MouseWheel Page" >
    
< GrID  x:name ="LayoutRoot" >
        
< StackPanel  HorizontalAlignment ="left"  OrIEntation ="Horizontal" >

            
<!--  
                在 Silverlight 4.0 中像 ListBox, DataGrID, ComboBox 这类的控件,如果出现了垂直滚动条的话,则可以通过滚动鼠标滚轮的方法来控制该滚动条
            
-->
            
< ListBox  name ="ListBox"  VerticalAlignment ="top"  WIDth ="100"  Height ="200" >
                
< ListBox.ItemTemplate >
                    
< DataTemplate >
                        
< StackPanel  OrIEntation ="Horizontal" >
                            
< TextBlock  Text =" {Binding} "  margin ="1"   />
                        
</ StackPanel >
                    
</ DataTemplate >
                
</ ListBox.ItemTemplate >
            
</ ListBox >
            
< sdk:DataGrID  name ="dataGrID"  VerticalAlignment ="top"  WIDth ="100"  Height ="200"  IsReadonly ="True"  autoGenerateColumns ="True"   />
            
< ComboBox  name ="comboBox"  VerticalAlignment ="top"  WIDth ="100"  Height ="20"  MaxDropDownHeight ="200"   />

            
<!--  
                用于演示如何响应鼠标的滚轮事件 
            
-->
            
< StackPanel >
                
< TextBlock  name ="lblMsg"  VerticalAlignment ="top"   />
                
< GrID  name ="grID"  WIDth ="100"  Height ="100" >
                    
< Rectangle  Fill ="Yellow"   />
                    
< TextBlock  Text ="Mouse wheel me"   />
                
</ GrID >
            
</ StackPanel >
            
        
</ StackPanel >
    
</ GrID >
</ navigation:Page >

MouseWheel.xaml.cs

代码 /*
 * 本例演示如何响应鼠标滚轮事件
 * UIElement.MouseWheel - 鼠标滚轮滚动时所触发的事件
 *     MouseWheelEventArgs.Delta - 滚轮向上滚动为正数;滚轮向下滚动为负数
 
*/

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;

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

        
protected   overrIDe   voID  OnNavigatedTo(NavigationEventArgs e)
        {
            List
< int >  List  =   new  List < int > ();
            
for  ( int  i  =   0 ; i  <   100 ; i ++ )
            {
                List.Add(i);
            }

            ListBox.ItemsSource 
=  List;
            dataGrID.ItemsSource 
=  List;
            comboBox.ItemsSource 
=  List;

            grID.MouseWheel 
+=   new  MouseWheelEventHandler(grID_MouseWheel);
        }

        
voID  grID_MouseWheel( object  sender, MouseWheelEventArgs e)
        {
            lblMsg.Text 
=   " Delta:  "   +  e.Delta;
        }
    }
}


4、演示如何响应鼠标右键事件
MouseRightClick.xaml

代码 < navigation:Page  x:Class ="Silverlight40.UI.MouseRightClick"  
           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
="MouseRightClick Page" >
    
< GrID  x:name ="LayoutRoot" >
        
< StackPanel  HorizontalAlignment ="left" >
            
            
< TextBlock  name ="lblMsg"  WIDth ="120"   />

            
< button  name ="button"  Content ="right click me"  WIDth ="120"   />
            
        
</ StackPanel >
    
</ GrID >
</ navigation:Page >

MouseRightClick.xaml.cs

代码 /*
 * 本例演示如何响应鼠标右键事件
 * UIElement.MouseRightbuttonDown - 鼠标右键按下时所触发的事件
 * UIElement.MouseRightbuttonUp  - 鼠标右键抬起时所触发的事件
 
*/

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;

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

        
protected   overrIDe   voID  OnNavigatedTo(NavigationEventArgs e)
        {
            button.MouseRightbuttonDown 
+=   new  MousebuttonEventHandler(button_MouseRightbuttonDown);
            button.MouseRightbuttonUp 
+=   new  MousebuttonEventHandler(button_MouseRightbuttonUp);
        }

        
voID  button_MouseRightbuttonDown( object  sender, MousebuttonEventArgs e)
        {
            lblMsg.Text 
=   " 鼠标右键 Down " ;
            e.Handled 
=   true ;
        }

        
voID  button_MouseRightbuttonUp( object  sender, MousebuttonEventArgs e)
        {
            lblMsg.Text 
=   " 鼠标右键 Up " ;
            e.Handled 
=   true ;
        }
    }
}


5、演示全屏的新特性
FullScreen.xaml

代码 < navigation:Page  x:Class ="Silverlight40.UI.FullScreen"  
           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
="FullScreen Page" >
    
< GrID  x:name ="LayoutRoot" >
        
        
< button  name ="btnFullScreen"  WIDth ="100"  Height ="50"  Content ="最大化/还原"  Click ="btnFullScreen_Click"   />
        
    
</ GrID >
</ navigation:Page >

FullScreen.xaml.cs

代码 /*
 * Application.Current.Host.Content.FullScreenoptions - 全屏的选项
 *     System.windows.Interop.FullScreenoptions.None - 当其他程序获得焦点时,退出全屏模式(默认值)
 *     System.windows.Interop.FullScreenoptions.StaysFullScreenWhenUnfocused - 当其他程序获得焦点时,保持全屏模式
 * 当设置为“StaysFullScreenWhenUnfocused”全屏时会d出对话框,要求用户确认是否使用“StaysFullScreenWhenUnfocused”的全屏模式。如果程序是“被信任的应用程序”则不会d出该对话框
 
*/

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;

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

        
protected   overrIDe   voID  OnNavigatedTo(NavigationEventArgs e)
        {

        }

        
private   voID  btnFullScreen_Click( object  sender, RoutedEventArgs e)
        {
            Application.Current.Host.Content.FullScreenoptions 
=  System.windows.Interop.FullScreenoptions.StaysFullScreenWhenUnfocused;
            Application.Current.Host.Content.IsFullScreen 
^=   true ;
        }
    }
}


OK
[源码下载] 总结

以上是内存溢出为你收集整理的稳扎稳打Silverlight(46) - 4.0UI之FlowDirection, TextTrimming, 响应鼠标滚轮事件, 响应鼠标右键事件, 全屏的新特性全部内容,希望文章能够帮你解决稳扎稳打Silverlight(46) - 4.0UI之FlowDirection, TextTrimming, 响应鼠标滚轮事件, 响应鼠标右键事件, 全屏的新特性所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1026556.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-23
下一篇 2022-05-23

发表评论

登录后才能评论

评论列表(0条)

保存