2010-12-04 2 views
0

私がしたいことは簡単に見えますが、何の結果もなく時間がかかります.. =/ 私はWPFウィンドウを持っていたいと思いますいくつかの所有権を持つオブジェクトとそれを使用してアイテムのカップルをポピュレートする。 は、具体的に受け取ったオブジェクトは、そのように定義されていますWPFのGUIとListBox/CheckBoxの2つの間のデータバインディング

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; } 
} 

と私はシミュレーションとShowSimulationsで2リストボックスを移入し、また、変数名と変更3チェックボックスに接続されている別のリストを持っているしたいのですが、その値リストで選択した項目を変更... Windowsのコード(.csファイル)は、次のとおりです。

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

結合のためのXAMLコードはこれです:

<Window x:Class="GUI.GraphicOptions" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    Title="GraphicOptions" Height="450" Width="350"> 
    <Grid> 
     <Grid.RowDefinitions> 
      <RowDefinition Height="25" /> 
      <RowDefinition Height="150"/> 
      <RowDefinition Height="25" /> 
      <RowDefinition Height="150"/> 
      <RowDefinition Height="25"/> 
      <RowDefinition Height="25" /> 
      <RowDefinition Height="11*" /> 
     </Grid.RowDefinitions> 
     <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" /> 
    </Grid> 
</Window> 

私は多くの方法で試してみましたが、常に唯一のアイテムをバインドするので、このライブラリーがどのように働くか、私は理解することはできません。.. 多くのおかげで、すべての4:P

質問です:任意の間違ったことがコードにあり私が投稿しました?

P.S:私の英語のため申し訳ありません:P

+0

あなたの質問を言い換えてください、そのお聞きしたいものをunderstnadことは本当に難しいですか? – TalentTuner

+0

WPFデータバインディングに関するチュートリアルを少なくとも1つ読んでおくことをお勧めします。 http://coredotnet.blogspot.com/2006/05/wpf-data-binding-tutorial.html – VVS

答えて

1

は、複数の項目を持つ単一のコントロールをバインドしないでください。 1つの選択された項目でバインドします。ここで

は正解です:

<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}" /> 
+0

ありがとうございました!今、私の問題を解決しようとします^^ " –

関連する問題