Görünüm modelimde (kullanıcı veri içeriğini denetler) gözlemlenebilir bir koleksiyona bağlanan bir liste kutusu var.DataTemplate içindeki bir düğmenin komutunu, ana öğenin veri içeriğine nasıl ayarlayabilirim
<Button Command="{Binding SimpleMethod}"/>
Her şey gayet:
DeviceDetector driveDetector;
public DriveSelector()
{
InitializeComponent();
driveDetector = DeviceDetector.Instance;
DataContext = driveDetector;
}
Bu benim liste
<ListBox Style="{StaticResource ListBoxStyle}" ItemsSource="{Binding DriveCollection}">
<ListBox.ItemTemplate>
<DataTemplate>
<Button Width="70" Style="{StaticResource DriveButtonStyle}" Command="{Binding SimpleMethod}">
<StackPanel>
<Image Source="{Binding Image}" Style="{StaticResource DriveImageStyle}"/>
<Label Content="{Binding Name}" Style="{StaticResource DriveLabelStyle}"/>
</StackPanel>
</Button>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
Ben iCommand uygulayan
ve ben şöyle liste dışında komuta bağlanan zaman benim kodudur.
System.Windows.Data Error: 40 : BindingExpression path error: 'SimpleMethod' property not found on 'object' ''DriveInfo' (HashCode=6377350)'. BindingExpression:Path=SimpleMethod; DataItem='DriveInfo' (HashCode=6377350); target element is 'Button' (Name=''); target property is 'Command' (type 'ICommand')
Ben düğmeye datacontext modeli ve böylece yönteme olduğunu görebilirsiniz 'SimpleMethod' bulunamıyor i düğmenin listbox en datatemplate içeriye komutu bağlamak için denemek Ancak bu hatası olsun . Komutu, liste kutusunun kendisinde bulunan veri konteynerine bağlayabilmemin bir yolu var mı?
Düğmeniz için özel bir davranış yazabilirsiniz. Bu şekilde düğmeye basacaksınız. Bilmiyorum, bu yöntem ne zaman kovulmalı? –