2017-11-08 1 views
1

콤보 상자에 기본값으로 'select'를 추가해야합니다.이 값을 데이터베이스에 추가 할 수 없습니다.이 위치 값은 동적입니다.이 값은 userrole에 따라 달라집니다. 나는 다른 방법으로 아무 것도 노력하지 못했습니다. 제발 도와주세요. wpf 콤보 상자의 기본값을 textBlock

<ComboBox Width="140" ItemsSource="{Binding SecurityContexts, Mode=OneWay}" 
         SelectedItem="{Binding ActiveSecurityContext, Mode=TwoWay}" 
         ToolTip="Working Location"> 
    <ComboBox.ItemTemplate> 
     <DataTemplate> 
      <TextBlock Text="{Binding Location}"/> 
     </DataTemplate> 
    </ComboBox.ItemTemplate> 
</ComboBox> 

코드 뒤에 SecurityContexts = ObservableCollection에 새로운 (_currentUser.ApplicationSecurityContexts)이고;

public interface IApplicationSecurityContext 
{ 
    IRole Role { get; } 
    string Location { get; } 
    IEnumerable<string> Budgets { get; } 

} 

public IApplicationSecurityContext ActiveSecurityContext 
    { 
     get { return this._currentUser.ActiveSecurityContext; } 
     set 
     { 
      if (this._currentUser.ActiveSecurityContext != value) 
      { 
       this._currentUser.ChangeActiveSecurityContext(value); 

       RaisePropertyChanged("CurrentUser"); 

       LoadData(); 
      } 
     } 
    } 
+1

것은 당신이 실제로가는 당신이 사용자 정의 개체를 정의 된 경로는 다음과 같습니다 당신은 당신의 항목이 C C에 그

참고 표시되는 방법을 정의 할 수도 자원의 컬렉션에 대한 귀하의 DataTemplate을 정의해야 : 콤보 상자 항목으로 표시되어야하는 "위치"속성을 노출하는 SecurityContexts 클래스 모음이 있습니다. 하나의 요소를 올바르게 추가하기 만하면됩니까? –

+0

오타와 죄송합니다. 그것은 나의 이전 코멘트에서 "가는"대신에 "하고있다". 그러나 당신이 우리에게 몇 가지 설명을하지 않으면 당신에게 대답을하기가 어려울 것입니다. 아마도 xaml뿐 아니라 특히 "SecurityContexts"가 무엇인지, 무엇이 만들어 졌는지 코드를 게시 할 수 있습니다. –

+0

추가 된 코드를 확인해 주셔서 감사합니다. 콤보 박스는 사용자의 역할에 따라 location1, location5 등을 표시합니다 ... 나는 단지 콤보 상자에 기본값 'select'를 추가해야합니다. – newbee

답변

0

당신은 당신이 할 수있는 CompositeCollection

사용하여 목표를 달성 할 수있다. 그리드/UserControl을/콤보 상자에서 자원을 정의

<Grid.Resources> 
     <CollectionViewSource x:Key="cvs" Source="{Binding Binding SecurityContexts, Mode=OneWay}" /> 
     <DataTemplate DataType="{x:Type c:SecurityContexts}"> 
      <TextBlock Text="{Binding Location}"/> 
     </DataTemplate> 
    </Grid.Resources> 

은 다음 콤보가 itemsource이 될 것입니다 : 그것은 작동해야

<ComboBox.ItemsSource> 
    <CompositeCollection> 
     <ComboBoxItem> 
     <TextBlock Text="select"/> 
     </ComboBoxItem> 
     <CollectionContainer Collection="{Binding Source= {StaticResource cvs}}"/> 
    </CompositeCollection> 
</ComboBox.ItemsSource> 

. SecurityContexts

+0

대니얼레에게 정말 감사드립니다. 당신이 제공 한 솔루션을 구현하려고 ... 문제가 있습니다.> SecurityContexts가 존재하지 않는다고 말합니다 ... 저는 WPF에 익숙하지 않습니다. .i 내가 뭔가 잘못하고 있다고 생각합니다. – newbee

+0

어쩌면 충분히 명확하지 않았을 것입니다. c : 앱이 SecurityContext를 찾을 수있는 경로를 나타냅니다. 그래서 UserControl에서 다음과 같이 정의해야합니다 : xmlns : c = "clr-namespace : yourProject.YourClass". –