原創|其它|編輯:郝浩|2012-03-07 02:34:04.000|閱讀 1194 次
概述:visifire中內置了5種主題,然而在實際項目中,你可以根據需要自定義visifire圖表主題。今天,我們一起來看看如何自定義visifire圖表主題和樣式。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
visifire中內置了5種主題,然而在實際項目中,你可以根據需要自定義visifire圖表主題。今天,我們一起來看看如何自定義visifire圖表主題和樣式。
如何使用一個默認主題:
visifire提供了5種內置主題,分別是:
1) Theme1.xaml
2) Theme2.xaml
3) Theme3.xaml
4) Theme4.xaml
5) Theme5.xaml
要使用visifire提供的主題,你必須設置Chart XAML中的Theme屬性,代碼如下:
<vc:Chart xmlns:vc="clr-namespace:Visifire.Charts;assembly=SLVisifire.Charts"
Theme="Theme1" Width="500" Height="300">
如何在silverlight程序中創建自定義主題:
第1步:創建一個silverlight托管代碼應用程序。
第2步:一旦在VS中創建了新的項目,找到Page.xaml文件,在"LayoutRoot" Grid 中編寫一個 chart XAML,并在<UserControl>標簽中將寬和高分別改為"500"和"300"。
藍色部分為修改 Page.xaml部分。
注:vc是用于創建Visifire圖表對象的命名空間。
<UserControl x:Class="SLVisifireApp.Page"
xmlns="//schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="//schemas.microsoft.com/winfx/2006/xaml"
xmlns:vc="clr-namespace:Visifire.Charts;assembly=SLVisifire.Charts"
Width="500" Height="300" >
<Grid x:Name="LayoutRoot" Background="White">
<vc:Chart xmlns:vc="clr-namespace:Visifire.Charts;assembly=SLVisifire.Charts" Width="500" Height="300" Theme="Theme1" >
<vc:Chart.Titles>
<vc:Title Text="Global Fortune 5 Companies 2007" />
</vc:Chart.Titles>
<vc:Chart.AxesX>
<vc:Axis Title="Companies" />
</vc:Chart.AxesX>
<vc:Chart.AxesY>
<vc:Axis Title="Revenue in Million dollars" />
</vc:Chart.AxesY>
<vc:Chart.Series>
<vc:DataSeries LegendText="Series1" RenderAs="Column" AxisYType="Primary" >
<vc:DataSeries.DataPoints>
<vc:DataPoint AxisXLabel="Wall-Mart" YValue="351139" />
<vc:DataPoint AxisXLabel="Exxon Mobil" YValue="345254" />
<vc:DataPoint AxisXLabel="Shell" YValue="318845" />
<vc:DataPoint AxisXLabel="BP" YValue="274316" />
<vc:DataPoint AxisXLabel="General Motors" YValue="207349" />
</vc:DataSeries.DataPoints>
</vc:DataSeries>
</vc:Chart.Series>
</vc:Chart>
</Grid>
</UserControl>
在添加了Chart XAML后,Page.xaml的效果如圖所示:
第3步:
在同一個應用程序域中創建一個自定義主題。
右鍵單擊SilverlightApplication文件夾,選擇Add > New Item,便會出現一個新的Add New Item 對話框,選擇“Silverlight User Control”,將其命名為“MyTheme.xaml”,點擊"Add",如圖所示:
第4步:
在Project Explorer中展開MyTheme.xaml,將顯示MyTheme.xaml.cs文件。因為我們不需要托管代碼文件時,刪除MyTheme.xaml.cs文件。
第5步:
一旦你點擊“Add”按鈕,便創建了MyTheme.xaml文件。刪除XAML文件中的所有內容,以ResourceDictionary取代它。
<ResourceDictionary
xmlns="//schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="//schemas.microsoft.com/winfx/2006/xaml"
xmlns:vc="clr-namespace:Visifire.Charts;assembly=SLVisifire.Charts"
>
</ResourceDictionary>
第6步:
在ResourceDictionary 標簽中為圖表元素創建圖表樣式。利用下面的代碼創建圖表和DataSeries的樣式。
<Style x:Key="Chart" TargetType="vc:Chart">
<Setter Property="Background" Value="Gray"/>
<Setter Property="View3D" Value="True"/>
<Setter Property="AnimationEnabled" Value="False"/>
</Style>
<Style x:Key="DataSeries" TargetType="vc:DataSeries">
<Setter Property="RadiusX" Value="5"/>
<Setter Property="RadiusY" Value="5"/>
<Setter Property="Color" Value="Orange"/>
</Style>
第7步:
一旦創建主題文件,找到MyTheme.xaml屬性,修改BuildAction to Content。
第8步:
將主題添加至Page.xaml,如下圖紅色邊框部分:
第9步:
運行Silverlight應用程序,便可查看到visifire圖表的自定義效果:
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn
文章轉載自:慧都控件網