WPF DataGrid绑定相关

yaj52125 2019-01-14 08:14:00
        <DataGrid Grid.ColumnSpan="5" Name="_dataGrid" ItemsSource="{Binding ThresholdValueList}" FontSize="12" CanUserAddRows="False" CanUserDeleteRows="False" CanUserResizeColumns="False" CanUserResizeRows="False" CanUserSortColumns="False">
<DataGrid.Columns>
<DataGridTextColumn Header="参数" Binding="{Binding IndicatorCaption}" Width="*" IsReadOnly="True"></DataGridTextColumn>
<DataGridComboBoxColumn Header="时间间隔" ItemsSource="{Binding DateIntervalList}" TextBinding="{Binding DateInterval,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" Width="*"></DataGridComboBoxColumn>
<DataGridComboBoxColumn Header="数据点数" ItemsSource="{Binding PointNumList}" TextBinding="{Binding DataPointNum,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" Width="*"></DataGridComboBoxColumn>
<DataGridTextColumn Header="最小值(%)" Binding="{Binding UserMinVal,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" Width="*"></DataGridTextColumn>
<DataGridTextColumn Header="最大值(%)" Binding="{Binding UserMaxVal,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" Width="*"></DataGridTextColumn>
</DataGrid.Columns>
</DataGrid>



    public class ThresholdValueModel : BindableBase
{
public int Index { get; set; }
public IndicatorEnum IndicatorID { get; set; }
public string IndicatorCaption { get; set; }
public CalcType CalculateType { get; set; }
public int DateInterval { get; set; }
public int DataPointNum { get; set; }
public float UserMinVal { get; set; }
public float UserMaxVal { get; set; }
public string Description { get; set; }
}



    public class BlockIndicatorSettingViewModel : BindableBase
{
private ObservableCollection<ThresholdValueModel> _thresholdValueList;
private List<int> _dateIntervalList = new List<int>() { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };
private List<int> _pointNumList = new List<int>() { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };
private bool _isWindowEnable;

public ObservableCollection<ThresholdValueModel> ThresholdValueList
{
get { return _thresholdValueList; }
set
{
_thresholdValueList = value;
OnPropertyChanged("ThresholdValueList");
}
}
public DelegateCommand OkButtonCommand { get; set; }
public List<int> DateIntervalList { get { return _dateIntervalList; } }
public List<int> PointNumList { get { return _pointNumList; } }
}


                BlockIndicatorSettingViewModel vm = new BlockIndicatorSettingViewModel();
BlockIndicatorSettingView view = new BlockIndicatorSettingView();
view.DataContext = vm;
view.ShowDialog();






我用上面代码实现DataGrid,并绑定数据,但是效果却是图片那样的。。
图上问题有两个
1:我明明只有前面5列,但是绑定后,Model中的property全显示出来了
2:第2列,第3列应该是下拉选项,但是没有显示

寻求高人指点
非常感谢





...全文
62 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
qq14923349 2019-01-15
  • 打赏
  • 举报
回复
第二个问题 试试去掉绑定看看

用这种爽些
<DataGridTemplateColumn Header="ID" Width="0.1*" >
<DataGridTemplateColumn.CellTemplate>
qq14923349 2019-01-15
  • 打赏
  • 举报
回复
第一个问题 AutoGenerateColumns="False"
groveer 2019-01-15
  • 打赏
  • 举报
回复
第一个问题解决了,第二个问题就不存在了

8,734

社区成员

发帖
与我相关
我的任务
社区描述
WPF/Silverlight相关讨论
社区管理员
  • WPF/Silverlight社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧