2011-02-15 4 views
0

Silverlight 그리드를 배치 한 Silverlight 자식 창을 사용하고 있습니다. 샘플 코드는 아래에 언급 : 네임 스페이스로Silverlight 하위 창에서 바인딩 문제가 발생했습니다.

<controls:ChildWindow x:Class="Bixi.Atlas.Client.UI.OrganisationModule.Views.CostCenters.Lookup" 
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
      xmlns:controls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls" 
      Width="400" Height="300" 
         xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk" 
      xmlns:viewmodel="clr-namespace:Bixi.Atlas.Client.UI.OrganisationModule.ViewModels.CostCenters" 
      Title="Lookup"> 

    <Grid x:Name="LayoutRoot" Margin="2" DataContext="{Binding PersonLookupVM, Source={StaticResource PersonLookupViewModel}}"> 
     <sdk:DataGrid AutoGenerateColumns="False" Height="550" Width="750" VerticalAlignment="Top" HorizontalAlignment="Left" Margin="0,0,0,0" Name="PersonDetailsGrid" 
         ItemsSource="{Binding Path=GetPersonDetails, Mode=TwoWay}"> 
      <sdk:DataGrid.Columns> 
       <sdk:DataGridTextColumn Width="100" IsReadOnly="True" Header="Person ID" Binding="{Binding PRS_PER_CODE, Mode=TwoWay}"></sdk:DataGridTextColumn> 
       <sdk:DataGridTextColumn Width="100" Header="Name" Binding="{Binding PRS_PER_NAME, Mode=TwoWay}"></sdk:DataGridTextColumn> 
       <sdk:DataGridTextColumn Width="100" Header="First name" Binding="{Binding PRS_PER_FIRSTNAME, Mode=TwoWay}"></sdk:DataGridTextColumn> 
       <sdk:DataGridTextColumn Width="100" Header="Country" Binding="{Binding PRS_PER_COUNTRY, Mode=TwoWay}"></sdk:DataGridTextColumn> 
      </sdk:DataGrid.Columns> 
      <!--<i:Interaction.Triggers> 
       <i:EventTrigger EventName="SelectionChanged"> 
        <i:InvokeCommandAction Command="{Binding SelectionChangedCommand}" CommandParameter="{Binding SelectedItems, ElementName=CostCentersGrid}" /> 
       </i:EventTrigger> 
      </i:Interaction.Triggers>--> 
     </sdk:DataGrid> 
    </Grid> 
</controls:ChildWindow> 

컨트롤은 내가 사용할 수 있습니다 :

<UserControl.Resources> 
    <viewmodel:ViewModelLocator x:Key="PersonLookupViewModel"/>  
</UserControl.Resources> 

내보기 모델 코드입니다 : 제대로 작동

using System; 
using System.Net; 
using System.Windows; 
using System.Windows.Controls; 
using System.Windows.Documents; 
using System.Windows.Ink; 
using System.Windows.Input; 
using System.Windows.Media; 
using System.Windows.Media.Animation; 
using System.Windows.Shapes; 
using Bixi.Atlas.Client.UI.OrganisationModule.Models.CostCenters; 
using System.Collections.Generic; 
using System.Linq; 
using Microsoft.Practices.Prism.Commands; 
using Bixi.Atlas.Client.UI.OrganisationModule.Views.CostCenters; 

namespace Bixi.Atlas.Client.UI.OrganisationModule.ViewModels.CostCenters 
{ 
    public class PersonLookupViewModel : ModelBase 
    { 
     List<PersonLookupModel> personLookupModel = new List<PersonLookupModel>(); 

     public List<PersonLookupModel> LoadPersonDetails() 
     { 
      personLookupModel.Add(new PersonLookupModel 
      { 
       PRS_PER_CODE = "1001", 
       PRS_PER_NAME = "Raj", 
       PRS_PER_FIRSTNAME = "Mehra", 
       PRS_PER_COUNTRY = "India" 

      }); 
      personLookupModel.Add(new PersonLookupModel 
      { 
       PRS_PER_CODE = "1002", 
       PRS_PER_NAME = "Dheeraj", 
       PRS_PER_FIRSTNAME = "Gupta", 
       PRS_PER_COUNTRY = "India" 
      }); 
      personLookupModel.Add(new PersonLookupModel 
      { 
       PRS_PER_CODE = "1003", 
       PRS_PER_NAME = "Gaurav", 
       PRS_PER_FIRSTNAME = "Puri", 
       PRS_PER_COUNTRY = "India" 
      }); 

      //this.GetPersonDetails = personLookupModel.AsQueryable(); 

      return personLookupModel; 
     } 

     IQueryable<CostCentersModel> mGetPersonDetails; 
     public IQueryable<CostCentersModel> GetPersonDetails 
     { 
      get { return mGetPersonDetails; } 
      set 
      { 
       mGetPersonDetails = value; 
       OnPropertyChanged("GetPersonDetails"); 
      } 
     } 


     public DelegateCommand LoadCommand { get; private set; } 



     //When the button is pressed in MainPage, executes method ExecuteOpenChildWindow 

     private MyDelegate _openChildWindow; 
     public MyDelegate OpenChildWindow 
     { 
      get 
      { 
       if (_openChildWindow == null) 
        _openChildWindow = new MyDelegate(executeOpenChildWindow); 
       return _openChildWindow; 
      } 

     } 

     // New instance of ChildWindow. Sets the NameProperty of the ChildWindow equal to the Name entered in the MainPage. 
     Lookup cw; 
     private void executeOpenChildWindow(object parameter) 
     { 

      cw = new Lookup(this); 
      //MyNameCW = MyNameVM; 
      cw.Show(); 
     } 

     //When OK-button is pressed in ChildWindow 
     private MyDelegate _okChildWindow; 
     public MyDelegate OkChildWindow 
     { 
      get 
      { 
       if (_okChildWindow == null) 
        _okChildWindow = new MyDelegate(OkSaveChildWindow); 
       return _okChildWindow; 
      } 

     } 

     //MainPage Address property is set to the value entered in the address textbox in Child Window. Child Window is closed. 

     private void OkSaveChildWindow(object parameter) 
     { 
      //MyAddressVM = MyAddressCW; 
      cw.Close(); 
     } 


     public PersonLookupViewModel() 
     { 
      LoadPersonDetails(); 

      LoadCommand = new DelegateCommand(() => LoadPersonDetails()); 
     } 
    } 
} 

답변

2
<controls:ChildWindow.Resources> 
    <viewmodel:ViewModelLocator x:Key="PersonLookupViewModel"/> 
</controls:ChildWindow.Resources> 
+0

감사합니다. – Neeraj

관련 문제