1
I have a Listbox that is dynamically loaded using EF. One of the filters used is that the product exists in stock.
var query = (from p in db.Products
join s in db.Stocks
on new { p.SchoolID, p.ProductID }
equals new { s.SchoolID, s.ProductID }
where
s.Quantity > 0 &&
p.Active == true &&
p.SchoolID == _idSchool &&
p.ProductTypeID == 1
select p);
lst.ItemsSource = query;
Code XAML of my Listbox...
<ListBox.ItemTemplate>
<DataTemplate>
<Grid>
<Border>
<StackPanel Margin="1">
<StackPanel.Background>
<ImageBrush ImageSource="images/btnSalgados.png"/>
</StackPanel.Background>
<TextBlock Margin="0,0,0,0" Padding="4" Width="167" Height="52" TextWrapping="Wrap" Text="{Binding Name}" ToolTip="{Binding Name}"
TextAlignment="Center" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="22" Foreground="White" />
<TextBlock Margin="0,0,0,0" Padding="4" Width="167" Height="40" TextWrapping="Wrap" Text="{Binding Price, StringFormat=\{0:N\}}"
TextAlignment="Center" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="22" Foreground="White"/>
</StackPanel>
</Border>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
The image of how Listbox appears for the user...
I need that if the user selects a product that only has 1 in the stock (because when selecting it the stock of it will be zeroed) this item will be disabled for future selections (so that it does not select a product that does not have in stock).
I don’t know if it doesn’t work because it’s a dynamic list or I have something really wrong. In Setter Property if I put the Active field that exists in the Products table it gets Enable = false but when I try to use this conversion class it does not get Disabled.
– Jhonas
I got it... Listboxitem item = (Listboxitem)lst.ItemContainerGenerator.Containerfromindex(lst.Selectedindex); item.Isenabled = false;
– Jhonas
As I do not have access to your code little more I can add unless the code I posted works, because I tested it and it is something I use frequently. Of course the
DataContext
ofListBox
must have a property calledquantidade
that receives the valueQuantity
that comes from the comic book, just like you have toName
andPrice
– ramaral
Yes the XAML part worked when I put a Field that comes from my Active BD. But when I tried to use the Quantity it accessed the Quantityboolconverter class...
– Jhonas