次の xaml コードを手続き型コードに変換しようとしています。
<docking:ToolWindow Title="{Binding ElementName=errorListView, Path=Items.Count, StringFormat={}Error List ({0}), FallbackValue=Error List}" >
<ListView x:Name="errorListView" BorderThickness="0">
<ListView.View>
<GridView>
<GridViewColumn Header="Line" Width="40" DisplayMemberBinding="{Binding Path=PositionRange.StartPosition.DisplayLine}" />
<GridViewColumn Header="Char" Width="40" DisplayMemberBinding="{Binding Path=PositionRange.StartPosition.DisplayCharacter}" />
<GridViewColumn Header="Description" Width="300" DisplayMemberBinding="{Binding Path=Description}" />
</GridView>
</ListView.View>
</ListView>
</docking:ToolWindow>
しかし、ToolWindow の Title の Binding と GridViewColumn の DisplayMemberBinding を行うのに問題があります。バインディングのために PositionRange.StartPosition.DisplayLine にアクセスする方法を知りたいです。
以下は私の試みです。
var toolWindow = new ToolWindow();
var errorlistView = new ListView { Name = "errorListView", BorderThickness = new Thickness(0)};
var gridView = new GridView();
var gridViewColumnLine = new GridViewColumn();
gridViewColumnLine.Header = "Line";
gridViewColumnLine.Width = 40;
var bindingDisplayLine = new Binding();
bindingDisplayLine.Path = new PropertyPath("PositionRange.StartPosition.DisplayLine");
-->BindingOperations.SetBinding(gridViewColumnLine, );
gridView.Columns.Add(gridViewColumnLine);
var gridViewColumnChar = new GridViewColumn();
gridViewColumnChar.Header = "Char";
gridViewColumnChar.Width = 40;
var bindingDisplayChar = new Binding();
bindingDisplayChar.Path = new PropertyPath("PositionRange.StartPosition.DisplayCharacter");
-->BindingOperations.SetBinding(gridViewColumnChar, );
gridView.Columns.Add(gridViewColumnChar);
var gridViewColumnDescription = new GridViewColumn();
gridViewColumnDescription.Header = "Description";
gridViewColumnLine.Width = 40;
var bindingDescription = new Binding();
bindingDescription.Path = new PropertyPath("Description");
-->BindingOperations.SetBinding(gridViewColumnDescription, )
gridView.Columns.Add(gridViewColumnDescription);
errorlistView.View = gridView;
var bnd = new Binding();
bnd.Source = errorlistView;
bnd.Path = new PropertyPath("Items.Count");
-->bnd.StringFormat = String.Format("Error List ({0})");
bnd.FallbackValue = "Error List";
BindingOperations.SetBinding(toolWindow, ToolWindow.TitleProperty, bnd);