こんにちは、ComboBox でのバインドに問題があります。ComboBox アイテムを ListView 列にバインドし、選択した列で定義された添付プロパティの値を選択値として返したいと思います。
以下の例では、選択した列の幅を表示する作業サンプルを確認できます。ComboBox のSelectedValuePathを(loc:SampleBehavior.SampleValue)に変更しようとすると、バインド エラーが発生します。
BindingExpression パス エラー: '(u:SearchableListView.SearchMemberPath)' プロパティが 'object' ''GridViewColumn' に見つかりません
<Window x:Class="Problem_Sample1.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:loc="clr-namespace:Problem_Sample1" WindowStartupLocation="CenterScreen" タイトル="Window1" 高さ="300" 幅="300"> <ドックパネル> <ComboBox DockPanel.Dock="トップ" x:Name="コンボボックス" ItemsSource="{Binding Path=View.Columns, ElementName=listview}" DisplayMemberPath="ヘッダー" SelectedValuePath="幅"> </コンボボックス> <StatusBar DockPanel.Dock="Bottom"> <テキストブロック> <TextBlock Text="選択した列 (値): " /> <TextBlock Text="{Binding Path=SelectedValue, ElementName=combobox}" /> </テキストブロック> </ステータスバー> <ListView x:Name="リストビュー"> <ListView.View> <グリッドビュー> <GridViewColumn Header="名前" 幅="101" loc:SampleBehavior.SampleValue="201" /> <GridViewColumn Header="姓" 幅="102" loc:SampleBehavior.SampleValue="202" /> </GridView> </ListView.View> </ListView> </ドックパネル> </ウィンドウ>
SampleBehavior.cs
System.Windows を使用します。 System.Windows.Controls を使用します。 名前空間 Problem_Sample1 { パブリック静的クラス SampleBehavior { public static readonly DependencyProperty SampleValueProperty = DependencyProperty.RegisterAttached( "サンプル値", typeof (int)、 typeof (SampleBehavior)); [AttachedPropertyBrowsableForType(typeof(GridViewColumn))] public static int GetSampleValue(GridViewColumn 列) { return (int)column.GetValue(SampleValueProperty); } [AttachedPropertyBrowsableForType(typeof(GridViewColumn))] public static void SetSampleValue(GridViewColumn 列、int 値) { column.SetValue(SampleValueProperty, 値); } } }
助けや提案をありがとう。