【发布时间】:2011-10-22 17:30:00
【问题描述】:
出于各种原因,我正在尝试将此 xaml 绑定转换为对应的 C#:
<ListView x:Name="eventListView" Grid.Column="0" Grid.Row="1" Background="LightGray" BorderThickness="0">
<local:EventCell x:Name="cell" Width="{Binding ActualWidth, Converter={StaticResource ListViewWidthConverter}, ElementName=eventListView, Mode=OneWay}"/>
</ListView>
我已经阅读了很多有类似问题的问题并想出了这个代码:
Binding b = new Binding();
b.Source = eventListView;
b.Path = new PropertyPath(cell.Width);
b.Converter = new ListViewWidthConverter();
b.Mode = BindingMode.OneWay;
cell.SetBinding(ListView.ActualWidthProperty, b);
但是 C# 代码无法编译,我不知道为什么。
【问题讨论】:
-
为什么代码不能编译?什么错误?
标签: c# wpf xaml data-binding