2010-06-10 3 views
0

안녕하세요, 저는 ComboBox에서 바인딩 문제가 있습니다. ComboBox 항목을 ListView 열에 바인딩하고 선택한 값으로 선택한 열에 정의 된 연결된 속성의 값을 반환하고 싶습니다.ComboBox에서 'SelectedValuePath'로 '연결된 속성'을 정의하는 방법은 무엇입니까?

아래 예제에서는 선택한 열의 너비를 표시하는 작업 예제를 볼 수 있습니다. 당신이 에 콤보 상자에 SelectedValuePath을 변경 (LOC : SampleBehavior.SampleValue)하려고하면 :

BindingExpression 경로 오류 :을 당신은 바인딩 오류 '(유 : SearchableListView.SearchMemberPath)'속성 '개체'를 찾을 수 없습니다 ''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" 
    Title="Window1" 
    Height="300" Width="300"> 
    <DockPanel> 
    <ComboBox DockPanel.Dock="Top" 
     x:Name="combobox" 
     ItemsSource="{Binding Path=View.Columns, ElementName=listview}" 
     DisplayMemberPath="Header" 
     SelectedValuePath="Width"> 
    </ComboBox> 

    <StatusBar DockPanel.Dock="Bottom"> 
     <TextBlock> 
     <TextBlock Text="Selected column (value): " /> 
     <TextBlock Text="{Binding Path=SelectedValue, ElementName=combobox}" /> 
     </TextBlock> 
    </StatusBar> 

    <ListView x:Name="listview"> 
     <ListView.View> 
     <GridView> 
      <GridViewColumn Header="Name" 
        Width="101" 
        loc:SampleBehavior.SampleValue="201" /> 
      <GridViewColumn Header="Surname" 
        Width="102" 
        loc:SampleBehavior.SampleValue="202" /> 
     </GridView> 
     </ListView.View> 
    </ListView> 
    </DockPanel> 
</Window> 

 

SampleBehavior.cs

어떤 도움이나 제안에 대한
 
using System.Windows; 
using System.Windows.Controls; 

namespace Problem_Sample1 
{ 
    public static class SampleBehavior 
    { 

    public static readonly DependencyProperty SampleValueProperty = 
     DependencyProperty.RegisterAttached(
     "SampleValue", 
     typeof (int), 
     typeof (SampleBehavior)); 

    [AttachedPropertyBrowsableForType(typeof(GridViewColumn))] 
    public static int GetSampleValue(GridViewColumn column) 
    { 
     return (int)column.GetValue(SampleValueProperty); 
    } 

    [AttachedPropertyBrowsableForType(typeof(GridViewColumn))] 
    public static void SetSampleValue(GridViewColumn column, int value) 
    { 
     column.SetValue(SampleValueProperty, value); 
    } 

    } 
} 
617,451,515,는

 

감사합니다.

답변

0

나는 이것 (그리고 그것은 몇 가지 합리적인 검색을위한 첫 번째 Google 결과)에 비틀 거 렸기 때문에, 나는 지금도 대답을 쓸 수 있습니다.

요청 된 기능은 실제로 요청 된 것과 정확히 동일한 방식으로 사용할 수 있습니다.

<ComboBox DockPanel.Dock="Top" 
    x:Name="combobox" 
    ItemsSource="{Binding Path=View.Columns, ElementName=listview}" 
    DisplayMemberPath="Header" 
    SelectedValuePath="(loc:SampleBehavior.SampleValue)"> 

첨부 된 속성 경로는 (중괄호)로 묶어야합니다. 그렇지 않으면 원본 개체에서 이상한 조회가 시도됩니다. "속성 '객체' ''GridViewColumn '에없는 BindingExpression 경로 오류 :'(SearchableListView.SearchMemberPath 유) '"때문에 오류 메시지가 확실히 관련이

또한

, 문제 지역에서의 오류 메시지 완전히 다른 속성이지 "(loc : SampleBehavior.SampleValue)"이 아닙니다. 이 불일치는 코드 샘플을 줄이기 위해 수행 된 편집과 관련된 문제인 것 같습니다.

관련 문제