Xamarin devexpress datagrid 样式

DevExpress的提供的内置,可以应用到主题GridControl改变其外观。

 

主题

iOS

Android


(默认适用于iOS

黑暗
(默认为Android

应用预定义的主题

主题类存储提供的主题名称。要更改主题,分配主题类的相应字段的ThemeManager.ThemeName

 

   

C#

  

using Xamarin.Forms;

using DevExpress.Mobile.DataGrid.Theme;

   

// ...  

   

ThemeManager.ThemeName = Themes.Dark;

   

// ...  

   

自定义主题

要自定义应用的主题,使用ThemeBase类。它为您提供各种定制,使您可以更改主题的外观,并将其应用到电网。您可以使用这些定制来改变背景颜色,字体和所需的网格单元(头,属性组行等)


重要

要应用定制,调用ThemeManager.RefreshTheme方法。

ThemeBase类的属性提供访问不同的定制,你可以调整来改变外观设置(例如,字体属性,边框和背景颜色等)网格的相应的视觉元素(如数据单元格,行分组过滤器面板等)。在本实施例中,使用下面的定制。

   

为了跟踪时刻变化的主题,无论是处理ThemeManager.ThemeChanged事件或使用IThemeChangingHandler.OnThemeChanged方法。

这个例子定制光主题,因为它是在下面的图片中显示。

   

 

   

C#:MainPage.xaml.cs

  

using System;

using System.Collections.Generic;

using Xamarin.Forms;

using DevExpress.Mobile.DataGrid;

using DevExpress.Mobile.DataGrid.Theme;

   

namespace ThemeCustomizing {

   

public partial class MainPage : ContentPage {

   

int count = 0;

public MainPage() {

   

InitializeComponent();

   

   

TestOrdersRepository model = new TestOrdersRepository();

BindingContext = model;

   

ThemeManager.ThemeName = Themes.Light;

   

// Header customization.

ThemeManager.Theme.HeaderCustomizer.BackgroundColor = Color.FromRgb(187, 228, 208);

ThemeFontAttributes myFont = new ThemeFontAttributes("Verdana",

ThemeFontAttributes.FontSizeFromNamedSize(NamedSize.Large),

FontAttributes.None, Color.White);

ThemeManager.Theme.HeaderCustomizer.Font = myFont;

   

   

// Cell customization.

ThemeManager.Theme.CellCustomizer.SelectionColor = Color.FromRgb(186, 220, 225);

ThemeFontAttributes myFont1 = new ThemeFontAttributes("Verdana",

ThemeFontAttributes.FontSizeFromNamedSize(NamedSize.Medium),

FontAttributes.None, Color.Black);

ThemeManager.Theme.CellCustomizer.Font = myFont1;

   

   

// Various customization.

ThemeManager.Theme.TotalSumaryCustomizer.BackgroundColor = Color.FromRgb(163, 162, 168);

ThemeFontAttributes myFont2 = new ThemeFontAttributes("Verdana",

ThemeFontAttributes.FontSizeFromNamedSize(NamedSize.Default),

FontAttributes.None, Color.Black);

ThemeManager.Theme.TotalSummaryCustomizer.Font = myFont2;

ThemeManager.Theme.NewItemRowCustomizer.Font = myFont2;

   

   

ThemeManager.RefreshTheme();

}

   

void OnCalculateCustomSummary(object sender, CustomSummaryEventArgs e) {

if (e.FieldName.ToString() == "Shipped")

if (e.IsTotalSummary) {

if (e.SummaryProcess == CustomSummaryProcess.Calculate) {

if (!(bool)e.FieldValue)

count++;

e.TotalValue = count;

}

}

}

   

}

   

}

自定义模板列、滑动显示按钮

<dxGrid:GridControl x:Name="grid" ItemsSource="{Binding JDProduct}"

AllowResizeColumns="True"

AllowHorizontalScrollingVirtualization="True"

ColumnsAutoWidth="False"

SwipeButtonShowing="OnSwipeButtonShowing"
						


						SwipeButtonClick="OnSwipeButtonClick"
					

>

<dxGrid:GridControl.Columns>

<dxGrid:TemplateColumn FieldName="Name" Caption ="112" Width ="60" IsReadOnly="true" AllowGroup="False" AllowSort="False" >

<dxGrid:TemplateColumn.DisplayTemplate>

<DataTemplate>

<Button Text="{Binding Value}"

Clicked="nameClient"

BorderWidth="0"

                                    BackgroundColor="Green"

                                    TextColor="White"

></Button>

</DataTemplate>

</dxGrid:TemplateColumn.DisplayTemplate>

</dxGrid:TemplateColumn>

<dxGrid:TextColumn FieldName="Name" Caption = "名字" Width = "100" />

<dxGrid:NumberColumn FieldName="UnitPrice" Caption = "价格" DisplayFormat="C0"/>

<dxGrid:DateColumn FieldName="Date" DisplayFormat="d"/>

<dxGrid:SwitchColumn FieldName="Shipped" />

<dxGrid:TextColumn FieldName="Name" Caption = "Product" />

<dxGrid:TextColumn FieldName="Name" Caption = "Product" />

<dxGrid:TextColumn FieldName="Name" Caption = "Product" />

<dxGrid:TextColumn FieldName="Name" Caption = "Product" />

<dxGrid:TextColumn FieldName="Name" Caption = "Product" />

<dxGrid:TextColumn FieldName="Name" Caption = "Product" />

 

</dxGrid:GridControl.Columns>

<dxGrid:GridControl.LeftSwipeButtons>

<dxGrid:SwipeButtonInfo ButtonName="LeftButton" Caption="打印" BackgroundColor="Green" Width="150"/>

</dxGrid:GridControl.LeftSwipeButtons>

</dxGrid:GridControl>

特殊说明:如果直接使用绑定的文本则使用 Value关键字,绑定对象则可以直接使用Value.XXX

后端.cs代码绑定事件

void OnSwipeButtonShowing(object sender, DevExpress.Mobile.DataGrid.SwipeButtonShowingEventArgs e)

{

if ((!(Boolean)grid.GetCellValue(e.RowHandle, "Shipped"))

&& (e.ButtonInfo.ButtonName == "RightButton"))

{

e.IsVisible = false;

}

}

 

void OnSwipeButtonClick(object sender, DevExpress.Mobile.DataGrid.SwipeButtonEventArgs e)

{

if (e.ButtonInfo.ButtonName == "LeftButton")

{

string orderDate = (string)grid.GetCellValue(e.RowHandle, " Name");

string orderDateDay = orderDate;

DisplayAlert("Alert from " + e.ButtonInfo.ButtonName, "Day: " + orderDateDay, "OK");

}

if (e.ButtonInfo.ButtonName == "RightButton")

{

grid.DeleteRow(e.RowHandle);

}

}

转载于:https://www.cnblogs.com/sephiroth-wzc/p/5312831.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值