Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/apache-flex/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
C# Itemscontrol内的WPF数据绑定备用datacontext_C#_Wpf_Xaml_Data Binding_Datacontext - Fatal编程技术网

C# Itemscontrol内的WPF数据绑定备用datacontext

C# Itemscontrol内的WPF数据绑定备用datacontext,c#,wpf,xaml,data-binding,datacontext,C#,Wpf,Xaml,Data Binding,Datacontext,我试图做的是将ItemsControl.ItemTemplate生成的控件绑定到ContactInterface类的新实例,该类在我运行查询函数时创建 ContactInterface.cs: class ContactInterface : INotifyPropertyChanged { public string Type { get; set; } private string firstname; public string FirstName {

我试图做的是将ItemsControl.ItemTemplate生成的控件绑定到ContactInterface类的新实例,该类在我运行查询函数时创建

ContactInterface.cs:

class ContactInterface : INotifyPropertyChanged
{
    public string Type { get; set; }

    private string firstname;
    public string FirstName { 
        get{return this.firstname;}
        set {
            if (this.firstname != value) {
                this.firstname = value;
                this.NotifyPropertyChanged("FirstName");
            }
        }
    }
        public event PropertyChangedEventHandler PropertyChanged;

        public void NotifyPropertyChanged(string propName)
        {
            if (this.PropertyChanged != null)
                this.PropertyChanged(this, new PropertyChangedEventArgs(propName));
        }
    }
}
SQL.cs

partial class MainWindow
{
    private void selectContact(int? contactID)
    {
        using (ContactsDataContext context = new ContactsDataContext("Data Source=ds;Initial Catalog=db;Integrated Security=True"))
        {
            Contact contact = context.Contacts.SingleOrDefault(x => x.ContactID == contactID);
            Contact spouse = context.Contacts.SingleOrDefault(x => x.ContactID == contact.Spouse);
            Property property = context.Properties.SingleOrDefault(x => x.PropertyID == contact.Address);

            ContactInterface selectedContact= new ContactInterface();

            selectedContact.FirstName = contact.FirstName;

            profileGrid.DataContext = selectedContact;
        }

    }
MainWindow.xaml

            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="300" />
                    <ColumnDefinition Width="*" />
                </Grid.ColumnDefinitions>
                <ItemsControl Name="Profile_Page_Controls">
                    <ItemsControl.ItemsPanel>
                        <ItemsPanelTemplate>
                            <Grid Margin="15">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="100" />
                                    <ColumnDefinition Width="30" />
                                    <ColumnDefinition Width="100" />
                                </Grid.ColumnDefinitions>
                                <Grid.RowDefinitions>
                                <RowDefinition Height="43" />
                                <RowDefinition Height="43" />
                                <RowDefinition Height="43" />
                                <RowDefinition Height="43" />
                                <RowDefinition Height="43" />
                                <RowDefinition Height="43" />
                                <RowDefinition Height="43" />
                                <RowDefinition Height="43" />

                            </Grid.RowDefinitions>
                            </Grid>
                        </ItemsPanelTemplate>
                    </ItemsControl.ItemsPanel>
                    <ItemsControl.ItemTemplate>
                        <DataTemplate>
                            <StackPanel>
                                <TextBlock Text="{Binding TextContent}"/>
                                <TextBox Height="23" Text="{Binding Path=FirstName, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged }"/>
                            </StackPanel>
                        </DataTemplate>
                    </ItemsControl.ItemTemplate>
                <ItemsControl.ItemContainerStyle>
                    <Style>
                        <Setter Property="Grid.Column" Value="{Binding profile_Column}" />
                        <Setter Property ="Grid.Row" Value="{Binding profile_Row}" />
                        <Setter Property="Grid.ColumnSpan" Value="{Binding profile_Colspan}" />
                    </Style>
                </ItemsControl.ItemContainerStyle>
            </ItemsControl>
                <CheckBox Name="profile_SpouseCheck" Grid.Column="1" Margin="0,0,0,0" Checked="profile_SpouseCheck_Checked_1" Unchecked="profile_SpouseCheck_Checked_1"> Spouse</CheckBox>


            </Grid>

配偶
我的计划是每次用户运行selectContact()函数时创建一个新的ContactInterface实例。该新实例将绑定到生成的控件,因此当用户进行更改并保存更改时,文本框将更新该ContactInterface实例,我的其他功能可以从该ContactInterface获取数据以对数据库进行更改


有什么想法吗?

这可能应该属于codereview.stackexchange.com,我甚至不知道codereview.stackexchange.com的存在。我会在那里转寄的,谢谢。