DataBinding Between a WPF GUI and a couple of ListBox/CheckBox

The thing i want to do looks easy, but takes me a lot of time without any result.. =/ I'd like to have a WPF window which takes an object with some proprieties and used it to popolate a couple of item. In the specific the object recieved is so defined:

public class ParameterForGraphicOptions
    public List<VariablesOptions> Variables { get; set; }
    public List<string> Simulations { get; set; }
    public List<string> ShowSimulations { get; set; }
public class VariablesOptions
    public string Name { get; set; }
    public bool Show { get; set; }
    public bool Average { get; set; }
    public bool Var { get; set; }

And i'd like to populate 2 ListBox with Simulations and ShowSimulations, and also have another list which is connected to Variables Name and 3 check box which change their values when you change the selected item in the list.. The Windows code (.cs) follows:

public GraphicOptions(ParameterForGraphicOptions pfgo) //NAME OF THE WINDOW
    InitializeComponent();                     //STD CALL
    this.DataContext = pfgo;                   //CONNECTING THE DATA CONTEXT

The XAML code for binding is this:

<Window x:Class="GUI.GraphicOptions"
    Title="GraphicOptions" Height="450" Width="350">
            <RowDefinition Height="25" />
            <RowDefinition Height="150"/>
            <RowDefinition Height="25" />
            <RowDefinition Height="150"/>
            <RowDefinition Height="25"/>
            <RowDefinition Height="25" />
            <RowDefinition Height="11*" />
        <Label Grid.Row="0">Simulation in Progress</Label>
        <Label Margin="188,0,0,0">Simulation to Show</Label>
        <ListBox Grid.Row="1" Height="150" HorizontalAlignment="Left" Name="Simulations" VerticalAlignment="Top" Width="140" />  
        <ListBox Grid.Row="1" Height="150" HorizontalAlignment="Left" Margin="188,0,0,0" Name="SimulationsToShow" VerticalAlignment="Top" Width="140" />
        <Label Grid.Row="2">Variables to Show</Label>

        <ListBox Grid.Column="0" Grid.Row="3" DataContext="{Binding Variables.Name}" Height="150" HorizontalAlignment="Left" Name="Variables" VerticalAlignment="Top" Width="140"  Grid.RowSpan="2" />
        <CheckBox Grid.Row="3" Content="Show" IsChecked="{Binding Variables.Show}"  Height="20" HorizontalAlignment="Left" Name="Show" VerticalAlignment="Top" Width="76" Margin="163,5,0,0" />
        <CheckBox Grid.Row="3" Content="Average" IsChecked="{Binding Variables.Average}"  Height="25"  HorizontalAlignment="Left" Name="Average" VerticalAlignment="Top" Width="76" Margin="174,54,0,0" Checked="Average_Checked" />
        <CheckBox Grid.Row="3" Content="Var" IsChecked="{Binding Variables.Var}" Height="25"  HorizontalAlignment="Left" Name="Variance" VerticalAlignment="Top" Width="76" Margin="163,31,0,0" />
        <CheckBox Content="Refresh Graphic During Computation" Grid.Row="5" Height="25" HorizontalAlignment="Left" Name="Continuos" VerticalAlignment="Top" Width="220" />
        <Button Content="Save" Grid.Row="5" Height="23" HorizontalAlignment="Left" Margin="253,1,0,0" Name="Save" VerticalAlignment="Top" Width="75" Click="Save_Click" />
        <Button Content="->" Grid.Row="1" Height="35" HorizontalAlignment="Left" Margin="145,30,0,0" Name="OneSimulation" VerticalAlignment="Top" Width="35" />
        <Button Content="=>" Grid.Row="1" Height="35" HorizontalAlignment="Left" Margin="145,65,0,0" Name="AllSimulation" VerticalAlignment="Top" Width="35" />

I tried in many ways, but always bind only a item, so I can't understand HOW this library works.. Many thanks 4 all :P

The question is: is there any wrong thing in the code i posted?

P.S.: Sorry for my English :P


Don't bind a single control with plural items. Bind with a single selected item.

Here is a correct solution:

<ListBox x:Name="vars" ItemsSource="{Binding Variables}" DisplayMemberPath="Name" />
<CheckBox IsChecked="{Binding SelectedItem.Show, ElementName=vars, Mode=TwoWay}" />
<CheckBox IsChecked="{Binding SelectedItem.Average, ElementName=vars, Mode=TwoWay}" />
<CheckBox IsChecked="{Binding SelectedItem.Var, ElementName=vars, Mode=TwoWay}" />

Need Your Help

Receipt formate in star TSp654 POS printer setting

iphone thermal-printer

I have established printer connection with my ipad , Now I want to set formate of receipt like alignment, horizontal tab, font size logo settings and all the things which is required in my receipt,

Issue with auto-complete widgets in JavaScript

javascript widget

I am using an auto-complete widget in java script to show a list of available books in a store. The widget is working and I already saw the array of books in the console log but it does not show th...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.