Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/silverlight/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Silverlight子窗口中的绑定问题_Silverlight_Silverlight 4.0 - Fatal编程技术网

Silverlight子窗口中的绑定问题

Silverlight子窗口中的绑定问题,silverlight,silverlight-4.0,Silverlight,Silverlight 4.0,我正在使用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="h

我正在使用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());
        }
    }
}
使用系统;
Net系统;
使用System.Windows;
使用System.Windows.Controls;
使用System.Windows.Documents;
使用System.Windows.Ink;
使用System.Windows.Input;
使用System.Windows.Media;
使用System.Windows.Media.Animation;
使用System.Windows.Shapes;
使用Bixi.Atlas.Client.UI.organizationmodule.Models.CostCenters;
使用System.Collections.Generic;
使用System.Linq;
使用Microsoft.Practices.Prism.Commands;
使用Bixi.Atlas.Client.UI.organizationModule.Views.CostCenters;
命名空间Bixi.Atlas.Client.UI.OrganizationModule.ViewModels.CostCenter
{
公共类PersonLookupViewModel:ModelBase
{
List personLookupModel=新列表();
公共列表LoadPersonDetails()
{
添加(新的personLookupModel
{
PRS_PER_CODE=“1001”,
PRS_PER_NAME=“Raj”,
PRS_PER_FIRSTNAME=“Mehra”,
PRS_PER_COUNTRY=“印度”
});
添加(新的personLookupModel
{
PRS_PER_CODE=“1002”,
PRS_PER_NAME=“Dheeraj”,
PRS_PER_FIRSTNAME=“Gupta”,
PRS_PER_COUNTRY=“印度”
});
添加(新的personLookupModel
{
PRS_PER_CODE=“1003”,
PRS_PER_NAME=“Gaurav”,
PRS_PER_FIRSTNAME=“Puri”,
PRS_PER_COUNTRY=“印度”
});
//this.GetPersonDetails=personLookupModel.AsQueryable();
返回personLookupModel;
}
易读的mGetPersonDetails;
公共IQueryable GetPersonDetails
{
获取{return mGetPersonDetails;}
设置
{
mGetPersonDetails=值;
OnPropertyChanged(“GetPersonDetails”);
}
}
public DelegateCommand LoadCommand{get;private set;}
//在主页面中按下按钮时,执行方法ExecutePenchildwinDow
私有MyDelegate\u openChildWindow;
公共MyDelegate OpenChildWindow
{
得到
{
如果(_openChildWindow==null)
_openChildWindow=新的MyDelegate(executeOpenChildWindow);
返回openChildWindow;
}
}
//新的ChildWindow实例。将ChildWindow的NameProperty设置为在主页中输入的名称。
查找连续波;
私有void executeOpenChildWindow(对象参数)
{
cw=新查找(此);
//MyNameCW=MyNameVM;
cw.Show();
}
//按下儿童窗口中的OK(确定)按钮时
私人MyDelegate_okChildWindow;
公共MyDelegate窗口
{
得到
{
如果(_okChildWindow==null)
_okChildWindow=新的MyDelegate(OkSaveChildWindow);
返回窗口;
}
}
//主页地址属性设置为在子窗口的地址文本框中输入的值。子窗口关闭。
私有void OkSaveChildWindow(对象参数)
{
//MyAddressVM=MyAddressCW;
cw.Close();
}
公众人物lookupviewmodel()
{
LoadPersonDetails();
LoadCommand=newdelegateCommand(()=>LoadPersonDetails());
}
}
}

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