You can read the full structure of my solution here , but here is a short link:
- I created the
Account.cs class in the Entities class library. - I created a
Core class library with the AccountController.cs class, which retrieves accounts from Sql server tables. - I created the
AccountWindowController.cs class in the AccountWindowController.cs class library. It contains the List<Account> Accounts property and calls the GetAccounts() method in the AccountController to populate this list. - Finally, I created
AccountWindow.xaml in the Gui.Wpf class Gui.Wpf . This WPF window contains a ListBox named AccountsListBox .
I want the data to bind the list box from AccountWindow to the list in AccountWindowController , but I don't know how to do this. Here is the relevant code:
AccountWindow.xaml
<Window x:Class="Gui.Wpf.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:controller="clr-namespace:Gui.Wpf.Controllers" Title="Accounts" Width="350" MinWidth="307" MaxWidth="400" Height="500" > <Window.Resources> <controller:AccountWindowController x:Key="AccountsCollection" /> </Window.Resources> <Grid> <ListBox Name="AccountsListBox" Margin="12,38,12,41" ItemsSource="{StaticResource ResourceKey=AccountsCollection}" /> </Grid> </Window>
AccountWindow.xaml.cs
public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); new Gui.Wpf.Controllers.AccountWindowController(); } }
AccountWindowController.cs
public class AccountWindowController {
Thanks for the help.
data-binding wpf binding
Boris
source share