2 个解决方案
#1
最简单的是用数据绑定,当列绑定的类型是整形时,输入时自然就只能输入整形。
<UserControl
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:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk" x:Class="SilverlightApplication1111.MainPage"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="400">
<Grid x:Name="LayoutRoot" Background="White">
<sdk:DataGrid x:Name="dg1" AutoGenerateColumns="False" HorizontalAlignment="Left" Height="238" Margin="10,10,0,0" VerticalAlignment="Top" Width="314">
<sdk:DataGrid.Columns>
<sdk:DataGridTextColumn Header="此列只能是数字" Binding="{Binding MyNumber}"/>
</sdk:DataGrid.Columns>
</sdk:DataGrid>
</Grid>
</UserControl>
using System;
using System.Collections.Generic;
using System.Windows.Controls;
namespace SilverlightApplication1111
{
public partial class MainPage : UserControl
{
public MainPage()
{
InitializeComponent();
this.dg1.ItemsSource = new List<MyTest>{
new MyTest{ MyNumber=1}
};
}
public class MyTest
{
public Int32 MyNumber { get; set; }
}
}
}
#2
非常非常感谢你~!!!
#1
最简单的是用数据绑定,当列绑定的类型是整形时,输入时自然就只能输入整形。
<UserControl
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:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk" x:Class="SilverlightApplication1111.MainPage"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="400">
<Grid x:Name="LayoutRoot" Background="White">
<sdk:DataGrid x:Name="dg1" AutoGenerateColumns="False" HorizontalAlignment="Left" Height="238" Margin="10,10,0,0" VerticalAlignment="Top" Width="314">
<sdk:DataGrid.Columns>
<sdk:DataGridTextColumn Header="此列只能是数字" Binding="{Binding MyNumber}"/>
</sdk:DataGrid.Columns>
</sdk:DataGrid>
</Grid>
</UserControl>
using System;
using System.Collections.Generic;
using System.Windows.Controls;
namespace SilverlightApplication1111
{
public partial class MainPage : UserControl
{
public MainPage()
{
InitializeComponent();
this.dg1.ItemsSource = new List<MyTest>{
new MyTest{ MyNumber=1}
};
}
public class MyTest
{
public Int32 MyNumber { get; set; }
}
}
}
#2
非常非常感谢你~!!!