我正在构建一个应用程序来显示绑定到一个ObservableCollection记录的datagrid,其中每个记录都有一个课程对象和一个ObservableCollection的结果对象。
课程使用自动填充框更改。 结果集合显示在具有IValueConverter实现的列表框中,以根据当前选定的课程的条件更改椭圆模板的颜色。
它的工作原理很好的加载,但通过自动完成对课程选择的后续更新不会触发重新计算/刷新值转换器。
有没有办法触发刷新XAML我添加UpdateSource =属性更改为列表框的绑定 - 但这会导致堆栈溢出(haha)。
这是代码:
< data:DataGrid x:Name =MyDatGrid> < data:DataGrid.Columns> < data:DataGridTemplateColumn Header =Results> < data:DataGridTemplateColumn.CellTemplate> < DataTemplate> < ListBox ItemsSource ={Binding ListOfResults}> < ListBox.ItemsPanel> < ItemsPanelTemplate> < StackPanel Orientation =Horizontal/> < / ItemsPanelTemplate> < /ListBox.ItemsPanel> < ListBox.ItemTemplate> < DataTemplate> < Ellipse Width =20Height =20Fill ={Binding Converter = {StaticResource resultToBrushConverter}}Stroke =BlackStrokeThickness =1/> < / DataTemplate> < /ListBox.ItemTemplate> < / ListBox> < / DataTemplate> < / data:DataGridTemplateColumn.CellTemplate> < / data:DataGridTemplateColumn> < data:DataGridTemplateColumn Header =Course> < data:DataGridTemplateColumn.CellTemplate> < DataTemplate> < Border> < input:AutoCompleteBox ItemsSource ={Binding Courses,Source = {StaticResource coursesSource}}/> < / Border> < / DataTemplate> < / data:DataGridTemplateColumn.CellTemplate>我设法在自动填充框中订阅了LostFocus事件,并重置了我已经拥有的过滤器数据网格但是,这是非常低效的? 刷新datagrid上的视图对该方法没有任何影响。
正确方向的任何步骤都将非常感谢。试图阻止自己再变灰:)
有没有想法在网格中获取列表的绑定表达式并更新它,但不知道?
感谢你们
解决方案首先确保Record对象实现INotifyPropertyChanged,Course属性调用
resultToBrushConverter中的转换器是否需要访问绑定对象的多个属性?如果它仅仅依赖于课程,而不是使用课程作为其路径。
修改:假设你确实有这些东西,你对Fill的约束应该如下所示: -
< Ellipse Width =20Height =20Fill ={Binding Coarse,Converter = {StaticResource resultToBrushConverter}}Stroke =BlackStrokeThickness =1/>现在,绑定知道监控Coarse属性,当PropertyChanged事件触发时,它应该更新Fill粗体财产。
I am building an application to display a datagrid bound to an ObservableCollection of Records, where each record has a Course Object and an ObservableCollection of Results Objects.
The course is changed using an autocomplete box. The results collection is displayed in a Listbox with an IValueConverter implementation to change the colour of the ellipse template based on criteria of the course currently selected.
It works great on loading, but subsequent updates to the course selection via the autocomplete does not trigger a recalculation/refresh of the value converter.
Is there a way to trigger the refresh in XAML. I added UpdateSource=Property changed to the binding of the list box - but this caused a stack overflow (haha).
Here is the code:
<data:DataGrid x:Name="MyDatGrid"> <data:DataGrid.Columns> <data:DataGridTemplateColumn Header="Results"> <data:DataGridTemplateColumn.CellTemplate> <DataTemplate> <ListBox ItemsSource="{Binding ListOfResults}"> <ListBox.ItemsPanel> <ItemsPanelTemplate> <StackPanel Orientation="Horizontal"/> </ItemsPanelTemplate> </ListBox.ItemsPanel> <ListBox.ItemTemplate> <DataTemplate> <Ellipse Width="20" Height="20" Fill="{Binding Converter={StaticResource resultToBrushConverter} }" Stroke="Black" StrokeThickness="1" /> </DataTemplate> </ListBox.ItemTemplate> </ListBox> </DataTemplate> </data:DataGridTemplateColumn.CellTemplate> </data:DataGridTemplateColumn> <data:DataGridTemplateColumn Header="Course" > <data:DataGridTemplateColumn.CellTemplate> <DataTemplate> <Border> <input:AutoCompleteBox ItemsSource="{Binding Courses, Source={StaticResource coursesSource}}"/> </Border> </DataTemplate> </data:DataGridTemplateColumn.CellTemplate>I managed to subscribe to the LostFocus Event on the autocomplete box and reset a filter that I already have on the datagrid. But isn;t this very inefficient ? Refreshing the view on the datagrid does not have any effect in that method.
Any steps in the right direction are greatly appreciated. Trying to prevent myself going anymore grey :)
Had thoughts of getting the binding expression of the list in the grid and updating it, but no clue ?
Thanks guys
解决方案First ensure that the Record object implements INotifyPropertyChanged and the Course property invokes it.
Does the converter in resultToBrushConverter require access to more than one property of the bound object? If it depends only on Course than use Course as its path.
Edit:
Assuming you do have these things in place your binding on Fill should look like:-
<Ellipse Width="20" Height="20" Fill="{Binding Coarse, Converter={StaticResource resultToBrushConverter} }" Stroke="Black" StrokeThickness="1" />Now that the binding knows its monitoring the Coarse property it should update the Fill when the PropertyChanged event fires for the Coarse property.
更多推荐
Silverlight更新/触发在DataGrid的Listbox DataTemplate中的IValueConverter
发布评论