XAML数据模板数据绑定 [英] Xaml datatemplate databinding

查看:83
本文介绍了XAML数据模板数据绑定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好!

在数据类和ui组件之间进行数据绑定时遇到以下问题.

在我的数据类中,我有多个属性,我想将这些属性(布尔,整数,双精度,字符串)绑定到我的数据网格中. DataClass具有多个实例,它还继承了INotifyPropertyChanged事件.我将我的DataClasses作为Collection带到datagrid.

这是我要执行的操作的简化代码:

Hi all!

I ran following problem when I made databindings between my dataclass and ui component.

In my dataclass I have multiple properties and I want to bind those properties (boolean, int, double, string) in my datagrid. DataClass has multiple instances, its also inherits INotifyPropertyChanged events. I bring my DataClasses to datagrid as Collection.

Here is simplified code of what I''m trying to do:

.
.
<Window.Resources>
<DataTemplate x:Key="booltemplate">
    <CheckBox IsChecked="{Binding Path=BoolProperty, Mode=TwoWay}"></CheckBox>
</DataTemplate>
</Window.Resources>
.
.
<DataGrid x:Name="dataGridWithDataTemplates"

  ItemsSource="{Binding Path=DataClassess}"

  AutoGenerateColumns="False"

  CanUserAddRows="False">
   <DataGrid.Columns>
    <!--Here I define each column individually, accordin my datatemplate-->
    <DataGridTemplateColumn Header="BoolProperty" CellTemplate="{StaticResource booltemplate}"></DataGridTemplateColumn>
   </DataGrid.Columns>
</DataGrid>
.
.


读取值时,此方法工作正常.更改Ui控件值(例如)时,此方法似乎也有效.取消选中复选框或在数据类实例属性中在文本框上进行BUT写入似乎没有什么变化,根本没有任何反应.感到有点沮丧.

我希望你有主意:)

Cheers


This works fine when it comes reading values, Its also seems working when changing Ui controls values eg. uncheking checkboxes or writing on the textbox BUT in dataclass instances properties seems to be unchanged, no reactions at all. Feels kinda frustrating..

I hope you got idea :)

Cheers

推荐答案

我希望看到您使用INotifyPropertyChanged实现的类.如果可能,请共享代码.希望您按照以下文章中的步骤进行操作.

http://msdn.microsoft.com/en-us/library/ms743695.aspx [ ^ ]
I would like to see your class implementation with INotifyPropertyChanged.If possible share the code.I hope you are following steps as in below article.

http://msdn.microsoft.com/en-us/library/ms743695.aspx[^]


这篇关于XAML数据模板数据绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆