我具有第一和第二ListView的,如所示的圖像中:綁定首先的ListView slected項第二ListView的
我填充第一ListView中,使用此代碼
class CategoriesList
{
public string Category_Names { get; set; }
public double Category_Amount { get; set; }
public static List<CategoriesList> get_CategoryList()
{
try
{
SQLiteConnection con = new SQLiteConnection(" Data Source=system.sqlite; Version=3; Compress=True; ");
con.Open();
string query = " SELECT category_id, category_name, amount FROM acc_income_category WHERE deleted = 0 ORDER BY category_name ASC ";
SQLiteCommand cmd = new SQLiteCommand(query, con);
SQLiteDataReader dr = cmd.ExecuteReader();
var categories = new List<CategoriesList>();
while (dr.Read())
{
CategoriesList cl = new CategoriesList();
cl.Category_Names = dr.GetString(1);
cl.Category_Amount = dr.GetDouble(2);
categories.Add(cl);
}
con.Close();
return categories;
}
catch (Exception ex)
{
System.Windows.MessageBox.Show(ex.Message);
return null;
}
}
}
這是我的Xaml代碼
<ListView x:Name="ListBox_Category_Names" VerticalAlignment="Stretch" HorizontalAlignment="Left"
Width="auto" Height="300" SelectionMode="Single" Grid.Column="0" Margin="0,0,10,0"
ScrollViewer.HorizontalScrollBarVisibility="Auto" ScrollViewer.VerticalScrollBarVisibility="Auto" SelectionChanged="ListBox_Category_Names_SelectionChanged"
>
<ListView.View>
<GridView>
<GridViewColumn Header="Category Name" DisplayMemberBinding="{Binding Category_Names}" Width="280" />
<GridViewColumn Header="Amount " DisplayMemberBinding="{Binding Category_Amount, ConverterCulture=ig-NG, StringFormat=\{0:C\}}" Width="130" />
</GridView>
</ListView.View>
</ListView>
<ListView x:Name="ListBox_Selected_Category" VerticalAlignment="Stretch" HorizontalAlignment="Stretch"
Width="auto" Height="300" SelectionMode="Single" Grid.Column="1" Margin="10,0,0,0"
ScrollViewer.HorizontalScrollBarVisibility="Auto" ScrollViewer.VerticalScrollBarVisibility="Auto"
ItemsSource="{Binding SelectedItem, ElementName=ListBox_Category_Names}" >
<ListView.View>
<GridView>
<GridViewColumn Header="Category Name" DisplayMemberBinding="{Binding Category_Names}" Width="250" />
<GridViewColumn Header="Amount" >
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBox x:Name="txtBox_amount" Text="{Binding Category_Amount, ConverterCulture=ig-NG, StringFormat=\{0:C\}}" Width="200" Height="35" />
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
這是代碼多數民衆贊成加載首先列表框
ListBox_Category_Names.ItemsSource = CategoriesList.get_CategoryList();
不MVVM
現在我堅持,因爲我需要在第一ListView中選定的項目綁定到二ListView控件。請,我真的需要幫助,在過去的三(3)周裏一直堅持這一點。提前致謝。
你可以發表你的'xaml'代碼呢? – SWilko
如何分配第一個列表視圖的項目源?你在使用MVVM嗎? – Firoz