2013-02-15 4 views
0

아래에 표시된 ComboBox가 있습니다. 코드 숨김이 항상 실행되지 않는 이유는 무엇입니까?WPF ComboBox가 선택 영역에서 실행되지 않습니다.

XAML :

<ComboBox Height="23" 
         Name="cbAppendCreate" 
         VerticalAlignment="Top" 
         Width="120" 
         Margin="{StaticResource ConsistentMargins}" 
         ItemsSource="{Binding Path=CbCreateAppendItems}" 
         SelectedValue="{Binding Path=CbAppendCreate,UpdateSourceTrigger=PropertyChanged}" /> 

코드 숨김 :

private string cbAppendCreate; 
public string CbAppendCreate { 
    get { 
     //.... 
     return cbAppendCreate 
    } 
    set { //This doesn't fire when selecting the first of 2 Items, 
      //but always fires when selecting the 2nd of two items 
      //.... 
     cbAppendCreate = value; 
    } 
} 
+0

출력 창에 바인딩 오류가 있습니까? – Haspemulator

+0

@Haspemulator 아니요 – sammarcow

+0

간단한 설정으로 재생할 수 없습니다. 원하는 경우 더 많은 코드를 게시하거나 광산을 게시 할 수 있습니다. – Haspemulator

답변

0

내가 아주 간단합니다, 여기 내 작업 코드를 게시 할 수 있습니다. 방금 VS2012 템플릿을 사용하여 기본 WPF 응용 프로그램을 만들었습니다.

<Window x:Class=" 
    WpfApplication1.MainWindow" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    Title="MainWindow" Height="350" Width="525"> 
<StackPanel> 
    <ComboBox Height="23" 
        Name="cbAppendCreate" 
        VerticalAlignment="Top" 
        Width="120" 
        ItemsSource="{Binding Path=CbCreateAppendItems}" 
        SelectedValue="{Binding Path=CbAppendCreate,UpdateSourceTrigger=PropertyChanged}" /> 
    <TextBlock Text="{Binding CbAppendCreate}"></TextBlock> 
</StackPanel> 

여기 코드 숨김입니다 : 여기 MainWindow.xaml 내용의

namespace WpfApplication1 
    { 
    public class DataSource 
    { 
     public List<string> CbCreateAppendItems { get; set; } 
     public string CbAppendCreate { get; set; } 
     public DataSource() 
     { 
      CbCreateAppendItems = new List<string>() { "create", "append" }; 
     } 
    } 
    /// <summary> 
    /// Interaction logic for MainWindow.xaml 
    /// </summary> 
    public partial class MainWindow : Window 
    { 
     public MainWindow() 
     { 
      InitializeComponent(); 
      DataContext = new DataSource(); 
     } 
    } 
} 

나는 콤보 상자에 다른 값을 선택하면 같은 값으로 TextBlock의 업데이트, 따라서 VM의 속성도 업데이트됩니다.

+0

나는 이것을 받아들이 기 때문에 모든 선택에 따라 작동하는 예제를 만들었지 만 문제는 원래대로 유지됩니다. setter가 ComboBox 값 변경에 대해 발사하지 않습니다. 나는 버그가 어디 있는지 모르겠습니다. – sammarcow

관련 문제