等效WPF绑定语法
我需要一些关于WPF绑定语法的帮助:等效WPF绑定语法,wpf,data-binding,Wpf,Data Binding,我需要一些关于WPF绑定语法的帮助: public class ApplicationPresenter { public ObservableCollection<Quotes> PriceList {get;} } public class WebSitePricesView { private IApplicationPresenter presenter { get { return (ApplicationPresenter)Da
public class ApplicationPresenter
{
public ObservableCollection<Quotes> PriceList {get;}
}
public class WebSitePricesView
{
private IApplicationPresenter presenter
{
get { return (ApplicationPresenter)DataContext; }
}
// public ObservableCollection<Quotes> PriceList
// {
// get {return presenter.PriceList; }
}
}
公共类应用程序演示器
{
公共ObservableCollection价格表{get;}
}
公共类网站价格视图
{
专用IApplicationPresenter演示者演示者
{
获取{return(ApplicationPresenter)DataContext;}
}
//公共可观测收集价格表
// {
//获取{return presenter.PriceList;}
}
}
此XAML工作正常:
<UserControl.Resources>
<ObjectDataProvider x:Key="ApplicationPresenterDS" ObjectType="{x:Type local:ApplicationPresenter}" />
<xcdg:DataGridCollectionViewSource x:Key="price_list" Source="{Binding Path=PriceList} />
</UserControl.Resources>
<xcdg:DataGridControl ItemsSource="{Binding Source={StaticResource price_list}} />
但是,我不希望WebSitePricesView公开PriceList,我希望将DataGridCollectionViewSource直接绑定到ApplicationPresenter.PriceList
此XAML不会将任何值绑定到网格。显然,我在定义价目表的绑定源时犯了一些错误
<UserControl.Resources>
<ObjectDataProvider x:Key="ApplicationPresenterDS" ObjectType="{x:Type local:ApplicationPresenter}" />
<xcdg:DataGridCollectionViewSource x:Key="price_list" Source="{Binding Source={StaticResource ApplicationPresenterDS}, Path=PriceList />
</UserControl.Resources>
<xcdg:DataGridControl ItemsSource="{Binding Source={StaticResource price_list}} />
第一次成功绑定的调试输出为:
Step into: Stepping over method without symbols 'Fenix.App.App'
System.Windows.Data Warning: 52 : Created BindingExpression (hash=35059110) for Binding (hash=15586314)
System.Windows.Data Warning: 54 : Path: 'PriceList'
System.Windows.Data Warning: 56 : BindingExpression (hash=35059110): Default mode resolved to OneWay
System.Windows.Data Warning: 57 : BindingExpression (hash=35059110): Default update trigger resolved to PropertyChanged
System.Windows.Data Warning: 58 : BindingExpression (hash=35059110): Attach to Xceed.Wpf.DataGrid.DataGridCollectionViewSource.Source (hash=28137373)
System.Windows.Data Warning: 60 : BindingExpression (hash=35059110): Use Framework mentor <null>
System.Windows.Data Warning: 63 : BindingExpression (hash=35059110): Resolving source
System.Windows.Data Warning: 65 : BindingExpression (hash=35059110): Framework mentor not found
System.Windows.Data Warning: 61 : BindingExpression (hash=35059110): Resolve source deferred
System.Windows.Data Warning: 91 : BindingExpression (hash=35059110): Got InheritanceContextChanged event from DataGridCollectionViewSource (hash=28137373)
System.Windows.Data Warning: 63 : BindingExpression (hash=35059110): Resolving source
System.Windows.Data Warning: 66 : BindingExpression (hash=35059110): Found data context element: WebSitePricesXc (hash=11090012) (OK)
System.Windows.Data Warning: 67 : BindingExpression (hash=35059110): DataContext is null
System.Windows.Data Warning: 52 : Created BindingExpression (hash=53154844) for Binding (hash=52037308)
System.Windows.Data Warning: 54 : Path: ''
System.Windows.Data Warning: 56 : BindingExpression (hash=53154844): Default mode resolved to OneWay
System.Windows.Data Warning: 57 : BindingExpression (hash=53154844): Default update trigger resolved to PropertyChanged
System.Windows.Data Warning: 58 : BindingExpression (hash=53154844): Attach to Xceed.Wpf.DataGrid.DataGridControl.ItemsSource (hash=16991442)
System.Windows.Data Warning: 63 : BindingExpression (hash=53154844): Resolving source
System.Windows.Data Warning: 66 : BindingExpression (hash=53154844): Found data context element: <null> (OK)
System.Windows.Data Warning: 72 : BindingExpression (hash=53154844): Use View from DataGridCollectionViewSource (hash=28137373)
System.Windows.Data Warning: 74 : BindingExpression (hash=53154844): Activate with root item <null>
System.Windows.Data Warning: 100 : BindingExpression (hash=53154844): Replace item at level 0 with <null>, using accessor {DependencyProperty.UnsetValue}
System.Windows.Data Warning: 97 : BindingExpression (hash=53154844): GetValue at level 0 from <null> using <null>: <null>
System.Windows.Data Warning: 76 : BindingExpression (hash=53154844): TransferValue - got raw value <null>
System.Windows.Data Warning: 85 : BindingExpression (hash=53154844): TransferValue - using final value <null>
A first chance exception of type 'System.FormatException' occurred in mscorlib.dll
System.Windows.Data Warning: 63 : BindingExpression (hash=35059110): Resolving source
System.Windows.Data Warning: 66 : BindingExpression (hash=35059110): Found data context element: WebSitePricesXc (hash=11090012) (OK)
System.Windows.Data Warning: 74 : BindingExpression (hash=35059110): Activate with root item ApplicationPresenter (hash=22260412)
System.Windows.Data Warning: 104 : BindingExpression (hash=35059110): At level 0 - for ApplicationPresenter.PriceList found accessor RuntimePropertyInfo(PriceList)
System.Windows.Data Warning: 100 : BindingExpression (hash=35059110): Replace item at level 0 with ApplicationPresenter (hash=22260412), using accessor RuntimePropertyInfo(PriceList)
System.Windows.Data Warning: 97 : BindingExpression (hash=35059110): GetValue at level 0 from ApplicationPresenter (hash=22260412) using RuntimePropertyInfo(PriceList): ObservableCollection`1 (hash=40261689 Count=0)
System.Windows.Data Warning: 76 : BindingExpression (hash=35059110): TransferValue - got raw value ObservableCollection`1 (hash=40261689 Count=0)
System.Windows.Data Warning: 85 : BindingExpression (hash=35059110): TransferValue - using final value ObservableCollection`1 (hash=40261689 Count=0)
System.Windows.Data Warning: 92 : BindingExpression (hash=53154844): Got PropertyChanged event from DataGridCollectionViewSource (hash=28137373) for View
System.Windows.Data Warning: 75 : BindingExpression (hash=53154844): Deactivate
System.Windows.Data Warning: 99 : BindingExpression (hash=53154844): Replace item at level 0 with {NullDataItem}
System.Windows.Data Warning: 72 : BindingExpression (hash=53154844): Use View from DataGridCollectionViewSource (hash=28137373)
System.Windows.Data Warning: 74 : BindingExpression (hash=53154844): Activate with root item DataGridCollectionView (hash=22444475 Count=0)
System.Windows.Data Warning: 100 : BindingExpression (hash=53154844): Replace item at level 0 with DataGridCollectionView (hash=22444475 Count=0), using accessor {DependencyProperty.UnsetValue}
System.Windows.Data Warning: 97 : BindingExpression (hash=53154844): GetValue at level 0 from DataGridCollectionView (hash=22444475 Count=0) using <null>: DataGridCollectionView (hash=22444475 Count=0)
System.Windows.Data Warning: 76 : BindingExpression (hash=53154844): TransferValue - got raw value DataGridCollectionView (hash=22444475 Count=0)
System.Windows.Data Warning: 85 : BindingExpression (hash=53154844): TransferValue - using final value DataGridCollectionView (hash=22444475 Count=0)
System.Windows.Data Warning: 91 : BindingExpression (hash=35059110): Got PropertyChanged event from ApplicationPresenter (hash=22260412)
System.Windows.Data Warning: 97 : BindingExpression (hash=35059110): GetValue at level 0 from ApplicationPresenter (hash=22260412) using RuntimePropertyInfo(PriceList): ObservableCollection`1 (hash=6408547 Count=27)
System.Windows.Data Warning: 76 : BindingExpression (hash=35059110): TransferValue - got raw value ObservableCollection`1 (hash=6408547 Count=27)
System.Windows.Data Warning: 85 : BindingExpression (hash=35059110): TransferValue - using final value ObservableCollection`1 (hash=6408547 Count=27)
System.Windows.Data Warning: 92 : BindingExpression (hash=53154844): Got PropertyChanged event from DataGridCollectionViewSource (hash=28137373) for View
System.Windows.Data Warning: 75 : BindingExpression (hash=53154844): Deactivate
System.Windows.Data Warning: 99 : BindingExpression (hash=53154844): Replace item at level 0 with {NullDataItem}
System.Windows.Data Warning: 72 : BindingExpression (hash=53154844): Use View from DataGridCollectionViewSource (hash=28137373)
System.Windows.Data Warning: 74 : BindingExpression (hash=53154844): Activate with root item DataGridCollectionView (hash=61423861 Count=27)
System.Windows.Data Warning: 100 : BindingExpression (hash=53154844): Replace item at level 0 with DataGridCollectionView (hash=61423861 Count=27), using accessor {DependencyProperty.UnsetValue}
System.Windows.Data Warning: 97 : BindingExpression (hash=53154844): GetValue at level 0 from DataGridCollectionView (hash=61423861 Count=27) using <null>: DataGridCollectionView (hash=61423861 Count=27)
System.Windows.Data Warning: 76 : BindingExpression (hash=53154844): TransferValue - got raw value DataGridCollectionView (hash=61423861 Count=27)
System.Windows.Data Warning: 85 : BindingExpression (hash=53154844): TransferValue - using final value DataGridCollectionView (hash=61423861 Count=27)
Step into: Stepping over method without symbols 'Fenix.App.App'
System.Windows.Data Warning: 52 : Created BindingExpression (hash=35059110) for Binding (hash=15586314)
System.Windows.Data Warning: 54 : Path: 'PriceList'
System.Windows.Data Warning: 56 : BindingExpression (hash=35059110): Default mode resolved to OneWay
System.Windows.Data Warning: 57 : BindingExpression (hash=35059110): Default update trigger resolved to PropertyChanged
System.Windows.Data Warning: 58 : BindingExpression (hash=35059110): Attach to Xceed.Wpf.DataGrid.DataGridCollectionViewSource.Source (hash=28137373)
System.Windows.Data Warning: 63 : BindingExpression (hash=35059110): Resolving source
System.Windows.Data Warning: 66 : BindingExpression (hash=35059110): Found data context element: <null> (OK)
System.Windows.Data Warning: 73 : BindingExpression (hash=35059110): Use Data from ObjectDataProvider (hash=61302538)
System.Windows.Data Warning: 74 : BindingExpression (hash=35059110): Activate with root item ApplicationPresenter (hash=20390146)
System.Windows.Data Warning: 104 : BindingExpression (hash=35059110): At level 0 - for ApplicationPresenter.PriceList found accessor RuntimePropertyInfo(PriceList)
System.Windows.Data Warning: 100 : BindingExpression (hash=35059110): Replace item at level 0 with ApplicationPresenter (hash=20390146), using accessor RuntimePropertyInfo(PriceList)
System.Windows.Data Warning: 97 : BindingExpression (hash=35059110): GetValue at level 0 from ApplicationPresenter (hash=20390146) using RuntimePropertyInfo(PriceList): ObservableCollection`1 (hash=12781633 Count=0)
System.Windows.Data Warning: 76 : BindingExpression (hash=35059110): TransferValue - got raw value ObservableCollection`1 (hash=12781633 Count=0)
System.Windows.Data Warning: 85 : BindingExpression (hash=35059110): TransferValue - using final value ObservableCollection`1 (hash=12781633 Count=0)
System.Windows.Data Warning: 52 : Created BindingExpression (hash=12661120) for Binding (hash=31408037)
System.Windows.Data Warning: 54 : Path: ''
System.Windows.Data Warning: 56 : BindingExpression (hash=12661120): Default mode resolved to OneWay
System.Windows.Data Warning: 57 : BindingExpression (hash=12661120): Default update trigger resolved to PropertyChanged
System.Windows.Data Warning: 58 : BindingExpression (hash=12661120): Attach to Xceed.Wpf.DataGrid.DataGridControl.ItemsSource (hash=16991442)
System.Windows.Data Warning: 63 : BindingExpression (hash=12661120): Resolving source
System.Windows.Data Warning: 66 : BindingExpression (hash=12661120): Found data context element: <null> (OK)
System.Windows.Data Warning: 72 : BindingExpression (hash=12661120): Use View from DataGridCollectionViewSource (hash=28137373)
System.Windows.Data Warning: 74 : BindingExpression (hash=12661120): Activate with root item DataGridCollectionView (hash=49343907 Count=0)
System.Windows.Data Warning: 100 : BindingExpression (hash=12661120): Replace item at level 0 with DataGridCollectionView (hash=49343907 Count=0), using accessor {DependencyProperty.UnsetValue}
System.Windows.Data Warning: 97 : BindingExpression (hash=12661120): GetValue at level 0 from DataGridCollectionView (hash=49343907 Count=0) using <null>: Data``GridCollectionView (hash=49343907 Count=0)
System.Windows.Data Warning: 76 : BindingExpression (hash=12661120): TransferValue - got raw value DataGridCollectionView (hash=49343907 Count=0)
System.Windows.Data Warning: 85 : BindingExpression (hash=12661120): TransferValue - using final value DataGridCollectionView (hash=49343907 Count=0)
A first chance exception of type 'System.FormatException' occurred in mscorlib.dll
单步执行:单步执行不带符号“Fenix.App.App”的方法
System.Windows.Data警告:52:为绑定(哈希=15586314)创建了BindingExpression(哈希=35059110)
System.Windows.Data警告:54:路径:“价格表”
System.Windows.Data警告:56:BindingExpression(哈希=35059110):默认模式解析为单向
System.Windows.Data警告:57:BindingExpression(哈希=35059110):默认更新触发器已解析为PropertyChanged
System.Windows.Data警告:58:BindingExpression(哈希=35059110):附加到Xceed.Wpf.DataGrid.DataGridCollectionViewSource.Source(哈希=28137373)
System.Windows.Data警告:60:BindingExpression(哈希=35059110):使用Framework mentor
System.Windows.Data警告:63:BindingExpression(哈希=35059110):正在解析源
System.Windows.Data警告:65:BindingExpression(哈希=35059110):找不到Framework mentor
System.Windows.Data警告:61:BindingExpression(哈希=35059110):解析源延迟
System.Windows.Data警告:91:BindingExpression(哈希=35059110):从DataGridCollectionViewSource(哈希=28137373)获取InheritanceContextChanged事件
System.Windows.Data警告:63:BindingExpression(哈希=35059110):正在解析源
System.Windows.Data警告:66:BindingExpression(哈希值=35059110):找到的数据上下文元素:WebSitePricesXc(哈希值=11090012)(确定)
System.Windows.Data警告:67:BindingExpression(哈希=35059110):DataContext为空
System.Windows.Data警告:52:为绑定(哈希=52037308)创建了BindingExpression(哈希=53154844)
System.Windows.Data警告:54:路径:“”
System.Windows.Data警告:56:BindingExpression(哈希=53154844):默认模式解析为单向
System.Windows.Data警告:57:BindingExpression(哈希=53154844):默认更新触发器已解析为PropertyChanged
System.Windows.Data警告:58:BindingExpression(哈希=53154844):附加到Xceed.Wpf.DataGrid.DataGridControl.ItemsSource(哈希=16991442)
System.Windows.Data警告:63:BindingExpression(哈希=53154844):正在解析源
System.Windows.Data警告:66:BindingExpression(哈希=53154844):找到数据上下文元素:(确定)
System.Windows.Data警告:72:BindingExpression(哈希=53154844):使用DataGridCollectionViewSource(哈希=28137373)中的视图
System.Windows.Data警告:74:BindingExpression(哈希=53154844):使用根项激活
System.Windows.Data警告:100:BindingExpression(hash=53154844):使用访问器{DependencyProperty.UnsetValue}将级别0处的项替换为
System.Windows.Data警告:97:BindingExpression(hash=53154844):使用以下命令获取级别0处的值:
System.Windows.Data警告:76:BindingExpression(哈希=53154844):TransferValue-获取原始值
System.Windows.Data警告:85:BindingExpression(哈希=53154844):TransferValue-使用最终值
mscorlib.dll中发生类型为“System.FormatException”的第一次意外异常
System.Windows.Data警告:63:BindingExpression(哈希=35059110):正在解析源
System.Windows.Data警告:66:BindingExpression(哈希值=35059110):找到的数据上下文元素:WebSitePricesXc(哈希值=11090012)(确定)
System.Windows.Data警告:74:BindingExpression(哈希=35059110):使用根项目ApplicationPresenter激活(哈希=22260412)
System.Windows.Data警告:104:BindingExpression(哈希=35059110):级别为0-对于ApplicationPresenter.PriceList,找到了访问者RuntimePropertyInfo(PriceList)
System.Windows.Data警告:100:BindingExpression(哈希=35059110):使用访问器RuntimePropertyInfo(PriceList)将级别为0的项替换为ApplicationPresenter(哈希=22260412)
System.Windows.Data警告:97:BindingExpression(hash=35059110):使用RuntimePropertyInfo(PriceList)从ApplicationPresenter(hash=22260412)获取级别为0的值:ObservableCollection`1(hash=40261689 Count=0)
System.Windows.Data警告:76:BindingExpression(哈希值=35059110):TransferValue-获取原始值ObservableCollection`1(哈希值=40261689计数=0)
System.Windows.Data警告:85:BindingExpression(哈希值=35059110):TransferValue-使用最终值ObservableCollection`1(哈希值=40261689计数=0)
System.Windows.Data警告:92:BindingExpression(哈希=53154844):从DataGridCollectionViewSource(哈希=28137373)获取视图的PropertyChanged事件
System.Windows.Data警告:75:BindingExpression(哈希=53154844):停用
System.Windows.Data警告:99:BindingExpression(哈希=53154844):将级别0处的项替换为{NullDataItem}
System.Windows.Data警告:72:BindingExpression(哈希=53154844):使用DataGridCollectionViewSource(哈希=28137373)中的视图
System.Windows.Data警告:74:BindingExpression(哈希=53154844):使用根项DataGridCollectionView激活(哈希=22444475计数=0)
System.Windows.Data警告:100:BindingExpression(hash=53154844):使用访问器{DependencyProperty.UnsetValue}将级别0处的项替换为DataGridCollectionView(hash=22444475 Count=0)
System.Windows.Data警告:97:BindingExpression(hash=53154844):使用:DataGridCollectionView(hash=22444475 Count=0)从DataGridCollectionView(hash=22444475 Count=0)获取级别0处的值
s
public class Quotes
{
public string Description { get; set; }
public decimal Value { get; set; }
}
public class ApplicationPresenter
{
public ApplicationPresenter()
{
PriceList = new ObservableCollection<Quotes>()
{
new Quotes(){Description="Quote One", Value=10m},
new Quotes(){Description="Quote Two", Value=10m},
new Quotes(){Description="Quote Three", Value=10m},
new Quotes(){Description="Quote Four", Value=10m},
};
}
public ObservableCollection<Quotes> PriceList { get; private set; }
}
<Window
x:Class="ObjectDataProviderPresenterSample.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:xcdg="http://schemas.xceed.com/wpf/xaml/datagrid"
xmlns:local="clr-namespace:ObjectDataProviderPresenterSample"
Title="Window1"
Height="300"
Width="300"
>
<Window.Resources>
<ObjectDataProvider
x:Key="ApplicationPresenterDS"
ObjectType="{x:Type local:ApplicationPresenter}"
/>
<xcdg:DataGridCollectionViewSource
x:Key="price_list"
Source="{Binding
Source={StaticResource ApplicationPresenterDS},
Path=PriceList}"
/>
</Window.Resources>
<Grid>
<xcdg:DataGridControl ItemsSource="{Binding Source={StaticResource price_list}}" />
</Grid>
</Window>