Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6607723
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T19:32:00+00:00 2026-05-25T19:32:00+00:00

I have parent window which has textBox called SchoolName, and a button called Lookup

  • 0

I have parent window which has textBox called “SchoolName”, and a button called “Lookup school Name”.

That Button opens a child window with list of school names. Now when user selects school Name from child window, and clicks on “Use selected school” button. I need to populate selected school in parent view’s textbox.

Note: I have adopted Sam’s and other people’s suggestion to make this code work. I have updated my code so other people can simply use it.

SelectSchoolView.xaml (Parent Window)

<Window x:Class="MyProject.UI.SelectSchoolView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Parent" Height="202" Width="547">
<Grid>
    <TextBox Height="23" Width="192" 
     Name="txtSchoolNames"  
     Text="{Binding Path=SchoolNames, UpdateSourceTrigger=PropertyChanged, 
     Mode=TwoWay}" 
     />

    <Label Content="School Codes" Height="28" HorizontalAlignment="Left" 
     Margin="30,38,0,0" Name="label1" VerticalAlignment="Top" />
    <Button Content="Lookup School Code" Height="30" HorizontalAlignment="Left" 
     Margin="321,36,0,0" Name="button1" VerticalAlignment="Top" Width="163" 
     Command="{Binding Path=DisplayLookupDialogCommand}"/>
</Grid>
</Window>

SchoolNameLookup.xaml (Child Window for Look up School Name)

<Window x:Class="MyProject.UI.SchoolNameLookup"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:toolkit="http://schemas.microsoft.com/wpf/2008/toolkit"
    Title="SchoolCodeLookup" Height="335" Width="426">

<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="226*" />
        <RowDefinition Height="70*" />
    </Grid.RowDefinitions>

    <toolkit:DataGrid Grid.Row="0" Grid.Column="1"   x:Name="dgSchoolList" 
                          ItemsSource="{Binding Path=SchoolList}" 
                          SelectedItem="{Binding Path=SelectedSchoolItem, Mode=TwoWay}" 
                          Width="294"
                          AutoGenerateColumns="False"
                          CanUserAddRows="False" 
                          CanUserDeleteRows="False"
                          CanUserResizeRows="False" 
                          CanUserSortColumns="True" 
                          SelectionMode="Single">

        <Button Grid.Row="1" Grid.Column="1" Content="Use Selected School Name" 
         Height="23" Name="btnSelect" Width="131" Command="{Binding 
         Path=UseSelectedSchoolNameCommand}"  />
 </Grid>
</Window>

SchoolNameLookupViewModel

   private string _schoolNames;
   public string SchoolNames
   {
        get { return _schoolNames; }
        set
        {
            _schoolNames= value;
            OnPropertyChanged(SchoolNames);
        }
   }

   private ICommand _useSelectedSchoolNameCommand;
   public ICommand UseSelectedSchoolNameCommand{
   get
    {
    if (_useSelectedSchoolNameCommand== null)
        _useSelectedSchoolNameCommand= new RelayCommand(a => 
            DoUseSelectedSchollNameItem(), p => true);
            return _useSelectedSchoolNameCommand;
      }
    set
       {
         _useSelectedSchoolNameCommand= value;
       }

    }

    private void DoUseSelectedSchoolNameItem() {
        StringBuilder sfiString = new StringBuilder();
        ObservableCollection<SchoolModel> oCol = 
                new ObservableCollection<SchoolModel>();
        foreach (SchoolModel itm in SchollNameList)
        {
            if (itm.isSelected) {
                sfiString.Append(itm.SchoolName + "; ");
                _schoolNames = sfiString.ToString();
            }
        }
                OnPropertyChanged(SchoolNames);
    }

    private ICommand _displayLookupDialogCommand;
    public ICommand DisplayLookupDialogCommand
    {
        get
        {
            if (_displayLookupDialogCommand== null)
                _displayLookupDialogCommand= new
                    RelayCommand(a => DoDisplayLookupDialog(), p => true);
            return _displayLookupDialogCommand;
        }
        set
        {
            _displayLookupDialogCommand= value;
        }
    }

    private void DoDisplayLookupDialog()
    {
        SchoolNameLookup snl = new SchoolNameLookup();
        snl.DataContext = this; //==> This what I was missing. Now my code works as I was expecting
        snl.Show();
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T19:32:01+00:00Added an answer on May 25, 2026 at 7:32 pm

    My solution is to bind both the windows to the same ViewModel, then define a property to hold the resulting value for codes, lets call it CurrentSchoolCodes, Bind the label to this property. Make sure that CurrentSchoolCodes raises the INotifyPropertyChanged event.
    then in the DoUseSelectedSchoolNameItem set the value for CurrentSchoolCodes.

    For properties in your models I suggest you to load them as they are required(Lazy Load patttern). I this method your property’s get accessor checks if the related field is still null, loads and assigns the value to it.
    The code would be like this code snippet:

    private ObservableCollection<SchoolModel> _schoolList;
    public ObservableCollection<SchoolModel> SchoolList{
        get {
            if ( _schoolList == null )
                _schoolList = LoadSchoolList();
            return _schoolList;
        }
    }
    

    In this way the first time your WPF control which is binded to this SchoolList property tries to get the value for this property the value will be loaded and cached and then returned.

    Note: I have to say that this kind of properties should be used carefully, since loading data could be a time consuming process. And it is better to load data in a background thread to keep UI responsive.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a parent window which has a ListView that is bound to an
I have a parent window in which a push-button's click event function has the
So I have this javascript code onclick of button for a child window which
I have a window which has 5 child windows. How can I close a
In my child window I have $('#opfile').addOption(someval,sometext); Problem is #opfile is an a parent
I have a parent object which has a one to many relationship with an
I have a parent project that is branched to many dependent child projects. I
I have a parent class which contains a child object. I am using set
I have a window which contains a Frame which references a 'home' page that
I have an aspx master/content page scenario. The parent page has an IFrame which

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.