09
2015
11

Silverlight 中 Color Brush 和 string 相互之间的转换 

 

1、String转换成Color

            Color color = (Color)ColorConverter.ConvertFromString(string);

2、String转换成Brush

            BrushConverter brushConverter = new BrushConverter();
            Brush brush = (Brush)brushConverter.ConvertFromString(string);

16
2015
10

telerik 的 RadDiagram控件 铅笔和钢笔工具默认不填充形状内的背景色

 

 

用铅笔和钢笔工具画图的时候, 形状默认会填充颜色, 如果是画形状还好,如果是画线的话就没必要填充颜色了, 设置如下:

 

首先要引用

xmlns:primitives="clr-namespace:Telerik.Windows.Controls.Diagrams.Primitives;assembly=Telerik.Windows.Controls.Diagrams"

 

11
2015
09

Silverlight多选下拉框控件CheckBox ComboBox

 Silverlight多选下拉框控件 ,把 ComboBox的 下拉框中放CheckBox控件实现多选,选过如下:


关键代码如下

前台 :



    <Grid x:Name="LayoutRoot" Background="White">
        <StackPanel Margin="10">
            <ComboBox Name="cmbDepartment" Height="25" Width="200" HorizontalAlignment="Left" >
                <ComboBox.ItemTemplate>
                    <DataTemplate>
                        <CheckBox Content="{Binding DepartmentName}" IsChecked="{Binding IsChecked,Mode=TwoWay}" />
                    </DataTemplate>
                </ComboBox.ItemTemplate>
            </ComboBox>
            <TextBlock x:Name="tbDepartment" Height="20" Width="Auto" MouseLeftButtonDown="TbDepartment_OnMouseLeftButtonDown" HorizontalAlignment="Left" Text="" Margin="5,-20,0,0" ></TextBlock>
        </StackPanel>
    </Grid>


01
2015
09

如何更改Telerik控件ChartView的坐标轴浮动标注的位置

            <telerik:RadCartesianChart.Behaviors>
                <telerik:ChartCrosshairBehavior PositionChanged="ChartCrosshairBehavior_PositionChanged" />
            </telerik:RadCartesianChart.Behaviors>

01
2015
09

XAML中的Format用法


在 XAML中这样使用


                <telerik:ChartCrosshairBehavior >
                    <telerik:ChartCrosshairBehavior.VerticalLineLabelDefinition >
                        <telerik:ChartAnnotationLabelDefinition VerticalAlignment="Top" Format="{}{0:yyyy-MM-dd HH:mm:ss}"/>
                    </telerik:ChartCrosshairBehavior.VerticalLineLabelDefinition>
                </telerik:ChartCrosshairBehavior>

25
2015
08

Silverlight动态给Grid添加TextBlock控件

 方法1 :


  protected void Dtable()
        {
            int numrows = 3;
            int numcells = 3;
            for (int j = 0; j < numrows; j++)
            {
                RowDefinition rd = new RowDefinition();
                LayoutRoot.RowDefinitions.Add(rd);

24
2015
08

Silverlight内存释放的问题

 

一、 脚本释放内存的方法



<script type="text/javascript">
    function intervalFlushMemory() {
        setInterval(FlushMemory, 60000);
    }

19
2015
04

asp.net页面中点击按钮传递给Silverlight,并且页面不刷新

转自http://blog.csdn.net/zdw_wym/article/details/7347548 

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Index.aspx.cs" Inherits="test.Index" %> 
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="
http://www.w3.org/1999/xhtml"> 
<head runat="server"> 
    <title></title> 
    <script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script> 
    <script src="Silverlight.js" type="text/javascript"></script> 
    <script type="text/javascript"> 
        function onSilverlightError(sender, args) { 
            var appSource = ""; 
            if (sender != null && sender != 0) { 
                appSource = sender.getHost().Source; 
            } 
 
            var errorType = args.ErrorType; 
            var iErrorCode = args.ErrorCode; 
 
            if (errorType == "ImageError" || errorType == "MediaError") { 
                return; 
            } 
 
            var errMsg = "Silverlight 应用程序中未处理的错误 " + appSource + "\n"; 
 
            errMsg += "代码: " + iErrorCode + "    \n"; 
            errMsg += "类别: " + errorType + "       \n"; 
            errMsg += "消息: " + args.ErrorMessage + "     \n"; 
 
            if (errorType == "ParserError") { 
                errMsg += "文件: " + args.xamlFile + "     \n"; 
                errMsg += "行: " + args.lineNumber + "     \n"; 
                errMsg += "位置: " + args.charPosition + "     \n"; 
            } 
            else if (errorType == "RuntimeError") { 
                if (args.lineNumber != 0) { 
                    errMsg += "行: " + args.lineNumber + "     \n"; 
                    errMsg += "位置: " + args.charPosition + "     \n"; 
                } 
                errMsg += "方法名称: " + args.methodName + "     \n"; 
            } 
 
            引发新错误(errMsg); 
        } 
    </script> 
</head> 
<body> 
    <form id="form1" runat="server"> 
    <div> 
        <asp:ScriptManager ID="ScriptManager1" runat="server"> 
        </asp:ScriptManager> 
        <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional"> 
            <ContentTemplate> 
                <input type="button" class="btn-search" value="查询" id="btnSearch" /> 
                <div style="width: 100%; height: 700px"> 
                    <object id="SL" data="data:application/x-silverlight-2," type="application/x-silverlight-2" 
                        width="100%" height="700px"> 
                        <param name="source" value="ClientBin/SL.xap" /> 
                        <param name="onError" value="onSilverlightError" /> 
                        <param name="background" value="white" /> 
                        <param name="minRuntimeVersion" value="4.0.60310.0" /> 
                        <param name="autoUpgrade" value="true" /> 
                        <param name="windowless" value="true" /> 
                        <a href="
http://go.microsoft.com/fwlink/?LinkID=149156&v=4.0.60310.0" style="text-decoration: none"> 
                            <img src="
http://go.microsoft.com/fwlink/?LinkId=161376" alt="获取 Microsoft Silverlight" 
                                style="border-style: none" /> 
                        </a> 
                    </object> 
                </div> 
            </ContentTemplate> 
        </asp:UpdatePanel> 
    </div> 
    </form> 
</body> 
</html> 
<script type="text/javascript" language="javascript"> 
    $(document).ready(function () { 
        $("#btnSearch").click(function () { 
            getMess(); 
        }); 
    }); 
 
    function getMess() { 
        $.post("Index.aspx", { 
            "action": "search", 
            "param": "level" 
        }, function (data) { 
            setTimeout(function () { 
                var slHost = document.getElementById("SL"); 
                var page = slHost.Content.Page; 
                page.process(data); 
            }, 1000); 
        }); 
    } 
</script> 

19
2015
04

ASP.NET传递参数到Silverlight


一、使用InitParams 


在Silverlight宿主页面加载时,我们在ASPX页面中获取参数,并作为初始化参数传递给Silverlight应用程序,如下代码所示:


protected void Page_Load(object sender, EventArgs e)
{
    this.Xaml1.InitParameters = String.Format("username={0},email={1}",
        Request.QueryString["username"],
        Request.QueryString["email"]);
}

27
2015
03

Silverlight减小XAP文件大小,提高文件加载速度

 

Silverlight项目发布的时候要勾选 “通过使用应用程序库缓存减小XAP大小”,如果引用的是库文件,还需要添加对应的extmap.xml 文件‘


假如项目引用的是库文件,如c:\project\ Microsoft.Windows.Controls.dll,那就在c:\project\ 目录下[不能在silverlight工程的bin\debug下]建立Microsoft.Windows.Controls.extmap.xml,具体内容参考如下:
  <?xml version="1.0"?>
  <manifest xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
   <assembly>
    <name>Microsoft.Windows.Controls</name>
    <version>2.0.21027.1502</version>
    <publickeytoken>31bf3856ad364e35</publickeytoken>
    <relpath>Microsoft.Windows.Controls.dll</relpath>
    <extension downloadUri="Microsoft.Windows.Controls.zip" />
   </assembly>
  </manifest>