Sem descrição

Jgrebnev 825fee4480 Обновить 'readme.md' há 6 meses atrás
.vs 9fd1fa3070 2 há 6 meses atrás
WpfApp1 9fd1fa3070 2 há 6 meses atrás
img 9fd1fa3070 2 há 6 meses atrás
WpfApp1.sln 9fd1fa3070 2 há 6 meses atrás
readme.md 825fee4480 Обновить 'readme.md' há 6 meses atrás

readme.md

Классы(Добавил чуть чуть кода в класс 4)

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;
            }
        }
    }

   

}
}

Mainwindow.xaml(Изменения с прошлой работы)

Добавил 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>

Mainwindow.xaml.cs

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;

Скрины работы