I have a printer model:
public class Printer: BindableBase
{
private bool isDefault = false;
public string Name { get; set; }
public bool IsDefault
{
get { return isDefault; }
set { SetProperty(ref isDefault, value); }
}
}
and a printer viewmodel:
public class PrinterViewModel: BindableBase
{
public ObservableCollection<Printer> Printers { get; set; }
public PrinterViewModel()
{
Printers = new ObservableCollection<Printer>();
LoadPrinters();
}
public void LoadPrinters()
{
Printers.Add(new Printer { Name = "HP" });
Printers.Add(new Printer { Name = "Sony" });
Printers.Add(new Printer { Name = "Samsung" });
Printers.Add(new Printer { Name = "LG" });
Printers.Add(new Printer { Name = "Toshiba" });
}
}
and a list box with an Itemtemplate so each item shows up with its Name in a TextBlock and a Button to change "IsDefault" property of this item:
<ListBox ItemsSource="{Binding Printers }">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Name}"/>
<Button x:Name="SetDefault" Content="Set as Default"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
Now, I want to change the "IsDefault" property of any item when its "SetDefault" button is clicked to 'true' and 'false' for all other items. how can I do that?
Thx in advance for any help.