Jgreb 9fd1fa3070 2 | 6 달 전 | |
---|---|---|
.vs | 6 달 전 | |
WpfApp1 | 6 달 전 | |
img | 6 달 전 | |
WpfApp1.sln | 6 달 전 | |
readme.md | 6 달 전 |
namespace WpfApp2.model
{
[DataContract]
public class Spares
{
[DataMember]
public string name { get; set; }
[DataMember]
public string detail { get; set; }
[DataMember]
public int price { get; set; }
[DataMember]
public string type { get; set; }
[DataMember]
public string photo { get; set; }
[DataMember]
public bool available { get; set; }
[DataMember(Name = "date")]
private string? stringdate { get; set; }
[IgnoreDataMember]
public DateTime? date
{
get
{
return stringdate == null ? null : DateTime.Parse(stringdate);
}
set
{
stringdate = value.ToString();
}
}
public Uri? ImageBitmap
{
get
{
var imageName = Environment.CurrentDirectory + "/img/" + (photo ?? "");
return System.IO.File.Exists(imageName) ? new Uri(imageName) : null;
}
}
}
}
}
ListBox DataGrid
<ListBox
Grid.Column="1"
Grid.Row="1"
Background="White"
ItemsSource="{Binding SparesList}" ScrollViewer.HorizontalScrollBarVisibility="Disabled">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel
HorizontalAlignment="Center" />
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.ItemTemplate>
<DataTemplate>
<Border
BorderThickness="1"
BorderBrush="Black"
CornerRadius="5">
<Grid
Width="200"
Margin="10"
HorizontalAlignment="Stretch">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="64"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="auto"/>
</Grid.ColumnDefinitions>
<Image
Width="64"
Height="64"
Source="{Binding ImageBitmap}" />
<StackPanel
Grid.Column="1"
Margin="5"
Orientation="Vertical">
<TextBlock
Text="{Binding name}"/>
<TextBlock
Text="{Binding deatail}"/>
</StackPanel>
<TextBlock
Grid.Column="2"
Text="{Binding price}"/>
</Grid>
</Border>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
InitializeComponent();
DataContext = this;
Globals.dataProvider = new JSONDataProvider();
SparesList = Globals.dataProvider.getSpares();
SparesDetailList = Globals.dataProvider.getDetail().ToList();
SparesDetailList.Insert(0, new SparesDetail { title = "" });
SparesPriceList = Globals.dataProvider.getPrice().ToList();
SparesTypeList = Globals.dataProvider.getType().ToList();
SparesTypeList.Insert(0, new SparesType { title = " " });
public class JSONDataProvider : LocalDataProvider, IDataProvider
{
private List<Spares> _SparesList;
public JSONDataProvider()
{
var serializer = new DataContractJsonSerializer(typeof(Spares[]));
using (var sr = new StreamReader("./data.json"))
{
_SparesList = ((Spares[])serializer.ReadObject(sr.BaseStream)).ToList();
}
}
public IEnumerable<Spares> getSpares()
{
return _SparesList;
}
}
private bool sortAsc = true;