Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wpf 如何手动刷新数据绑定?_Wpf_Inotifypropertychanged - Fatal编程技术网

Wpf 如何手动刷新数据绑定?

Wpf 如何手动刷新数据绑定?,wpf,inotifypropertychanged,Wpf,Inotifypropertychanged,我有一个基于大查询的数据模型,我希望将Linq查询的结果显示到网格中。 GUI将编辑属性,这将影响查询结果。但是,即使绑定执行得很好,调试器也不会显示PropertyChanged事件的订户(它是“null”)。我已经做了这个测试示例 我希望用户设置一系列标准,然后点击“执行”按钮。在我的示例中,我希望网格中的项目数会发生变化 以下是xaml: <Window x:Class="GridViewNotifyTest.MainWindow" xmlns="http://schemas

我有一个基于大查询的数据模型,我希望将Linq查询的结果显示到网格中。 GUI将编辑属性,这将影响查询结果。但是,即使绑定执行得很好,调试器也不会显示PropertyChanged事件的订户(它是“null”)。我已经做了这个测试示例

我希望用户设置一系列标准,然后点击“执行”按钮。在我的示例中,我希望网格中的项目数会发生变化

以下是xaml:

<Window x:Class="GridViewNotifyTest.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow" Height="350" Width="525">
<Grid>
    <StackPanel>
        <Button Click="Button_Click">Take 3</Button>
        <Button Click="Button_Click_1">Take 5</Button>
        <Button Click="Button_Click_2">FireNotify</Button>
    <DataGrid ItemsSource="{Binding}">
        <DataGrid.Columns>
            <DataGridTextColumn Binding="{Binding}"/>
        </DataGrid.Columns>            
    </DataGrid>
    </StackPanel>
</Grid>
</Window>

第三次
拿5块
FireNotify
这是C#:

命名空间GridViewNotifyTest
{
/// 
///MainWindow.xaml的交互逻辑
/// 
公共部分类主窗口:窗口,INotifyPropertyChanged
{
私人投资额;
公共主窗口()
{
初始化组件();
_takeAmount=4;
DataContext=金额;
}
私有无效按钮\u单击(对象发送者,路由目标e)
{
_takeAmount=3;
}
私有无效按钮\u单击\u 1(对象发送者,路由目标)
{
_takeAmount=5;
}
私有无效按钮\u单击\u 2(对象发送方,路由目标)
{
不动产价值变更(“金额”);
}
受保护的虚拟void OnPropertyValueChanged(字符串propertyName)
{
如果(PropertyChanged!=null)PropertyChanged(这是新的PropertyChangedEventArgs(propertyName));//调试器将PropertyChanged委托显示为null。
}
公帑
{
获取{return Enumerable.Range(1,10).Take(_takeAmount);}
}
公共事件属性更改事件处理程序属性更改;
}
}

DataContext
设置为
this
,然后将绑定更改为

<DataGrid ItemsSource="{Binding Amount}">


根据问题标题,快速回答将是使用方法。

这很有效。我现在知道GUI中没有任何东西绑定到通知对象。我认为这对GridView没有任何影响,因为GridView仍然“绑定到可枚举项”。但当然不是这样。“{Binding Amount}”只是设置“Path”属性的简写。修复后,bindingSOURCE是实现INotifyPropertyChanged的对象。谢谢
<DataGrid ItemsSource="{Binding Amount}">