我真的需要帮助。过去一周我一直坚持这一点。
我想在另一个ListBox内的ListBox中显示数据。 First ListBox正常工作,数据正确加载到该ListBox中。但是当我尝试在第二个ListBox中绑定数据时,问题出现了。
这是我拥有的ListBox:
<ListBox x:Name="myListBox" Margin="0,14,0,0" Grid.Row="1" ItemsSource="{Binding ElementName=myAutoComplete, Path=FilteredSuggestions}" >
<ListBox.ItemTemplate >
<DataTemplate>
<StackPanel>
<Grid Margin="0, 12, 0, 12" >
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Image Width="50" Height="50" Source="{Binding ImageSource}"/>
<TextBlock Foreground="White" FontSize="32" x:Name="Abc" Grid.Column="1" Margin="12,6,12,6" Text="{Binding CategoryName}" TextWrapping="Wrap" />
</Grid>
<Grid Margin="0,0,0,24">
<ListBox x:Name="myWorking" IsHitTestVisible="False" ItemsSource="{Binding ProdDesc}">
<ListBox.ItemTemplate>
<DataTemplate>
<Grid Margin="37,6">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Image Width="87" Height="87" Source="Images/Product.png"/>
<StackPanel Grid.Column="1">
<TextBlock Margin="12,-9,12,0" Grid.Column="1" Text="{Binding ProductName}" TextWrapping="Wrap" FontFamily="Segoe WP SemiLight" FontSize="{StaticResource PhoneFontSizeLarge}" Foreground="{StaticResource PhoneForegroundBrush}"/>
</StackPanel>
<Border Margin="0,9,0,12" BorderThickness="0,0,0,12" BorderBrush="#55555555" RenderTransformOrigin="0.5,0.5">
</Border>
<Border Margin="0,-41,0,12" BorderThickness="0,0,0,8" BorderBrush="White" RenderTransformOrigin="0.5,0.5">
<Border.RenderTransform>
<CompositeTransform SkewX="-40" />
</Border.RenderTransform>
</Border>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Grid>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
我想在ListBox中添加名为 myWorking
的数据但是当我尝试在CAM中添加代码或在XAML中绑定时,没有数据被加载。
这是我到目前为止在C#end中所做的代码。
我创建了一个名为 Prod_Description 的类:
class Prod_Description : INotifyPropertyProdged
{
public event PropertyProdgedEventHandler PropertyProdged;
public void OnPropertyProdged(PropertyProdgedEventArgs e)
{
if (PropertyProdged != null)
PropertyProdged(this, e);
}
public int _productid;
public int ProductId
{
get
{
return _productid;
}
set
{
if (_productid != value)
{
_productid = value;
OnPropertyProdged(new PropertyProdgedEventArgs("ProductId"));
}
}
}
public string _productname;
public string ProductName
{
get
{
return _productname;
}
set
{
if (_productname != value)
{
_productname = value;
OnPropertyProdged(new PropertyProdgedEventArgs("ProductName"));
}
}
}
public string _productlink;
public string ProductLink
{
get
{
return _productlink;
}
set
{
if (_productlink != value)
{
_productlink = value;
OnPropertyProdged(new PropertyProdgedEventArgs("ProductLink"));
}
}
}
public string _categoryname;
public string CategoryName
{
get
{
return _categoryname;
}
set
{
if (_categoryname != value)
{
_categoryname = value;
OnPropertyProdged(new PropertyProdgedEventArgs("CategoryName"));
}
}
}
public Prod_Description(string prodname, string proddesc, string catname)
{
this._productname = prodname;
this._productlink = proddesc;
this._categoryname = catname;
}
在我的 MainPage.xaml.cs 中,我编写了以下代码:
private ObservableCollection<Chan_Description> ProdDesc = new ObservableCollection<Prod_Description>();
在我的 PhoneApplicationPage_Loaded 方法中:
foreach (Pr_Description prod_Items in pr_DescriptionList) // pr_DescriptionList is a List where all the Items are stored
{
this.ProdDesc.Add(new Prod_Description(prod_Items.ProductName,prod_Items.ProductLink,prod_Items.CategoryName));
}
myAutoComplete.SuggestionsSource = ProdDesc;
this.myAutoComplete.FilterKeyProvider = (object item) =>
{
return ((item as Prod_Description).ProductName + (item as Prod_Description).ProductName);
};
我真的不知道我在这里失踪了什么。我已经搜索了很多网,但没有找到任何答案来解决这个问题。
所以,我的问题是,如何在 myWorking ListBox中绑定ItemsSource?我想在 myWorking ListBox中绑定 ProdDesc ObservableCollection。感谢。