WPF Datagrid 数字类型居右显示
项目中有大量的表格,想写个样式统一处理将数字居右显示!
public class DemoConverter : IMultiValueConverter
{
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
if (values[1] is System.Data.DataRow)
{
//change the text alignment left or right.
var cell = (System.Windows.Controls.DataGridCell)values[0];
var row = (System.Data.DataRow)values[1];
var columnName = cell.Column.SortMemberPath;
if (row[columnName] is int || (row[columnName] is decimal || row[columnName] is double))
return System.Windows.HorizontalAlignment.Right;
}
return System.Windows.HorizontalAlignment.Left;
}
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
{
return null;
}
}
<converts:DemoConverter x:Key="DemoConverter"></converts:DemoConverter>
<Style TargetType="{x:Type DataGridCell}">
<Setter Property="HorizontalAlignment">
<Setter.Value>
<MultiBinding Converter="{StaticResource DemoConverter}" >
<MultiBinding.Bindings>
<Binding RelativeSource="{RelativeSource Self}"/>
<Binding Path="Row" Mode="OneWay"/>
</MultiBinding.Bindings>
</MultiBinding>
</Setter.Value>
</Setter>
</Style>
<Binding Path="Row" Mode="OneWay"/> 其中的Row我该怎么改?以上代码是在网上找的例子!
public class DemoConverter : IMultiValueConverter
{
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
if (values[1] is System.Data.DataRow)
{
//change the text alignment left or right.
var cell = (System.Windows.Controls.DataGridCell)values[0];
var row = (System.Data.DataRow)values[1];
var columnName = cell.Column.SortMemberPath;
if (row[columnName] is int || (row[columnName] is decimal || row[columnName] is double))
return System.Windows.HorizontalAlignment.Right;
}
return System.Windows.HorizontalAlignment.Left;
}
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
{
return null;
}
}
<converts:DemoConverter x:Key="DemoConverter"></converts:DemoConverter>
<Style TargetType="{x:Type DataGridCell}">
<Setter Property="HorizontalAlignment">
<Setter.Value>
<MultiBinding Converter="{StaticResource DemoConverter}" >
<MultiBinding.Bindings>
<Binding RelativeSource="{RelativeSource Self}"/>
<Binding Path="Row" Mode="OneWay"/>
</MultiBinding.Bindings>
</MultiBinding>
</Setter.Value>
</Setter>
</Style>
<Binding Path="Row" Mode="OneWay"/> 其中的Row我该怎么改?以上代码是在网上找的例子!
...全文
相关推荐
WPF分页DataGrid
最近用到WPF的表格控件,需要使用分页功能,找了很多例子都不是很满意。有些是模仿SL做的DataPager导航条,使用的时候还要和DataGrid组合使用,不是很方便。最好还是继承DataGrid的分页表格控件。 于是自己动手封装了一个分页表格。
wpf datagrid 单元格颜色 根据datatable动态显示datagrid内容
wpf datagrid 单元格颜色 根据条件改变颜色换 根据表datatable动态显示datagrid内容
WPF动态添加行列DATAGRID
WPF DataGrid 动态添加 行列 比较靠谱的,可以看看,通俗易懂
WPF DataGrid 添加合计行并始终显示在底部代码
找了好长时间,终于找到wpf DataGrid添加合计行并始终显示在底部,并带有DataGrid 样式(隔行变色,鼠标移动变色,选中行变色)
WPF DataGrid 中显示图片的小例子
在WPF的 DataGrid控件中显示图片的小例子


