Ich habe ein verbindliches Problem. Vielleicht habe ich es nicht gesehen.Binding Probleme ViewModel mit Befehl
XAML Datei
<ItemsControl Grid.Row="1" Grid.Column="1" x:Name="itemsControlTiles" ItemsSource="{Binding ProductCatalogLightList}" Margin="10">
<ItemsControl.Template>
<ControlTemplate>
<WrapPanel Width="800" HorizontalAlignment="Left"
FlowDirection="LeftToRight" IsItemsHost="true">
</WrapPanel>
</ControlTemplate>
</ItemsControl.Template>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Controls:Tile Title="{Binding Name}"
Margin="3"
Background="{Binding Background}"
Style="{StaticResource PrdukteTileStyle}" >
<i:Interaction.Triggers>
<i:EventTrigger EventName="Click">
<i:InvokeCommandAction Command="{Binding Source={StaticResource productsTileViewModel}, Path=DoSomethingCommand}"
CommandParameter="{Binding ID,ElementName= ProductCatalogLightList}" />
</i:EventTrigger>
</i:Interaction.Triggers>
</Controls:Tile>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
So ist mein Problem das Command Bindung.
Meine Modelview sieht aus wie diese
public class Product_Catalog_Light
{
public string Name { get; set; }
public string Description { get; set; }
public int ID{ get; set; }
public System.Windows.Media.Brush Background { get; set; }
}
public class ProductsTileViewModel : INotifyPropertyChanged
{
private ObservableCollection<Product_Catalog_Light> _product_Catalog_LightList;
public ProductsTileViewModel()
{
ProductCatalogLightList = new ObservableCollection<Product_Catalog_Light>();
}
......
public ObservableCollection<Product_Catalog_Light> ProductCatalogLightList
{
get { return _product_Catalog_LightList; }
set
{
_product_Catalog_LightList = value;
OnPropertyChanged("ProductCatalogLightList");
}
}
}
public ICommand DoSomethingCommand
{
get
{
return _doSomethingCommand ??
(_doSomethingCommand = new DelegateCommand<int>(ExecuteDoSomethingWithItem));
}
}
private DelegateCommand<int> _doSomethingCommand;
private void ExecuteDoSomethingWithItem(int db_ID)
{
// Do something wir the _id
int i = 5;
}
ich eine Fehlermeldung erhalten, die sagt, dass es nicht die Bindungsquelle finden.
System.Windows.Data Error: 4 : Cannot find source for binding with reference 'ElementName=ProductCatalogLightList'. BindingExpression:Path=ID; DataItem=null; target element is 'InvokeCommandAction' (HashCode=11254959); target property is 'CommandParameter' (type 'Object')
Oh ja ... Vielen Dank !! – Ebc
@Ebc: Verwenden Sie [Snoop] (https://snoopwpf.codeplex.com/). Sie können den visuellen Baum durchqueren, um Eigenschaften zu sehen/ändern. Es kann Ihnen auch helfen, den aktiven DataContext eines Steuerelements zu sehen. – Anders