0
我想要做的事情看起來很容易,但需要我很多時間沒有任何結果.. =/ 我想有一個WPF窗口,它需要一個有一些禮節的物體,並用它來流行一些物品。 在收到特定對象被這樣定義:數據綁定之間的WPF圖形用戶界面和幾個列表框/複選框
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; }
}
,我想填充列表框2與模擬和ShowSimulations,並且還具有連接到變量名和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
請重新表述您的問題,它真的很難understnad你要問什麼? – TalentTuner 2010-12-04 12:00:01
我建議你閱讀至少一篇有關WPF數據綁定的教程。 http://coredotnet.blogspot.com/2006/05/wpf-data-binding-tutorial.html – VVS 2010-12-04 12:05:03