|
@@ -1,4 +1,4 @@
|
|
|
-**["Получение данных из внешних источников.JSON."](https://github.com/kolei/OAP/blob/master/articles/lab_wpf_data_json.md)**
|
|
|
+**["Вывод данных согласно макета (ListBox, Image)."](https://github.com/kolei/OAP/blob/master/articles/wpf_listbox.md)**
|
|
|
***
|
|
|
**C#**
|
|
|
***
|
|
@@ -32,6 +32,16 @@ namespace WpfApp1.model
|
|
|
public DateOnly? dateOfLastSTO { get; set; }
|
|
|
[DataMember]
|
|
|
public string? photo { get; set; }
|
|
|
+
|
|
|
+ public Uri? ImageBitmap
|
|
|
+ {
|
|
|
+ get
|
|
|
+ {
|
|
|
+ var imageName = Environment.CurrentDirectory + "/img/" + (photo ?? "");
|
|
|
+ return System.IO.File.Exists(imageName) ? new Uri(imageName) : null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
```
|
|
@@ -189,7 +199,7 @@ namespace WpfApp1.model
|
|
|
"color": "white",
|
|
|
"defects": false,
|
|
|
"dateOfLastSTO": "2024-12-05",
|
|
|
- "photo": null
|
|
|
+ "photo": "light2.jpg"
|
|
|
},
|
|
|
{
|
|
|
"name": "Toyota Supra A80",
|
|
@@ -198,7 +208,7 @@ namespace WpfApp1.model
|
|
|
"color": "white",
|
|
|
"defects": false,
|
|
|
"dateOfLastSTO": "2023-10-02",
|
|
|
- "photo": null
|
|
|
+ "photo": "light3.jpg"
|
|
|
},
|
|
|
{
|
|
|
"name": "Nissal Skyline R34",
|
|
@@ -207,7 +217,7 @@ namespace WpfApp1.model
|
|
|
"color": "gray",
|
|
|
"defects": false,
|
|
|
"dateOfLastSTO": "2024-11-05",
|
|
|
- "photo": null
|
|
|
+ "photo": "light4.jpg"
|
|
|
},
|
|
|
{
|
|
|
"name": "Toyota Camry 3.5",
|
|
@@ -216,7 +226,7 @@ namespace WpfApp1.model
|
|
|
"color": "black",
|
|
|
"defects": false,
|
|
|
"dateOfLastSTO": "2022-12-10",
|
|
|
- "photo": null
|
|
|
+ "photo": "light5.jpg"
|
|
|
},
|
|
|
{
|
|
|
"name": "Audi RS 65",
|
|
@@ -225,7 +235,7 @@ namespace WpfApp1.model
|
|
|
"color": "black",
|
|
|
"defects": false,
|
|
|
"dateOfLastSTO": "2023-12-07",
|
|
|
- "photo": null
|
|
|
+ "photo": "light6.jpg"
|
|
|
},
|
|
|
{
|
|
|
"name": "Трактор LOVOL TE354 HT",
|
|
@@ -234,7 +244,7 @@ namespace WpfApp1.model
|
|
|
"color": "blue",
|
|
|
"defects": false,
|
|
|
"dateOfLastSTO": "2021-12-10",
|
|
|
- "photo": null
|
|
|
+ "photo": "light7.jpg"
|
|
|
},
|
|
|
{
|
|
|
"name": "BMW M5 F90",
|
|
@@ -243,7 +253,7 @@ namespace WpfApp1.model
|
|
|
"color": "red",
|
|
|
"defects": false,
|
|
|
"dateOfLastSTO": "2024-04-10",
|
|
|
- "photo": null
|
|
|
+ "photo": "light8.jpg"
|
|
|
},
|
|
|
{
|
|
|
"name": "BMW E36",
|
|
@@ -252,7 +262,7 @@ namespace WpfApp1.model
|
|
|
"color": "black",
|
|
|
"defects": false,
|
|
|
"dateOfLastSTO": "2019-12-17",
|
|
|
- "photo": null
|
|
|
+ "photo": "light9.jpg"
|
|
|
},
|
|
|
{
|
|
|
"name": "Daewoo Matiz",
|
|
@@ -261,7 +271,7 @@ namespace WpfApp1.model
|
|
|
"color": "blue",
|
|
|
"defects": false,
|
|
|
"dateOfLastSTO": "2021-12-10",
|
|
|
- "photo": null
|
|
|
+ "photo": "light10.jpg"
|
|
|
}
|
|
|
]
|
|
|
```
|
|
@@ -525,6 +535,11 @@ namespace WpfApp1
|
|
|
xmlns:local="clr-namespace:WpfApp1"
|
|
|
mc:Ignorable="d"
|
|
|
Title="Иванов Валера И-21" Height="450" Width="908">
|
|
|
+ <Window.Resources>
|
|
|
+ <BitmapImage
|
|
|
+ x:Key='defaultImage'
|
|
|
+ UriSource='./bin/Debug/net8.0-windows/img/net.jpg' />
|
|
|
+ </Window.Resources>
|
|
|
<Grid ShowGridLines="True">
|
|
|
<Grid.RowDefinitions>
|
|
|
<RowDefinition Height="auto"/>
|
|
@@ -538,35 +553,62 @@ namespace WpfApp1
|
|
|
|
|
|
<!-- лого -->
|
|
|
<Image
|
|
|
- Source="./img/net.jpg"
|
|
|
+ Source="./bin/Debug/net8.0-windows/img/net.jpg"
|
|
|
Grid.RowSpan="2" HorizontalAlignment="Right"/>
|
|
|
- <DataGrid
|
|
|
+ <ListBox
|
|
|
Grid.Row="1"
|
|
|
- Grid.Column="1"
|
|
|
- CanUserAddRows="False"
|
|
|
- AutoGenerateColumns="False"
|
|
|
+ Grid.Column="1"
|
|
|
+ Background="White"
|
|
|
ItemsSource="{Binding CarList}">
|
|
|
- <DataGrid.Columns>
|
|
|
- <DataGridTextColumn
|
|
|
- Header="Название"
|
|
|
- Binding="{Binding name}"/>
|
|
|
- <DataGridTextColumn
|
|
|
- Header="Год"
|
|
|
- Binding="{Binding year}"/>
|
|
|
- <DataGridTextColumn
|
|
|
- Header="Цена"
|
|
|
- Binding="{Binding price}"/>
|
|
|
- <DataGridTextColumn
|
|
|
- Header="Цвет"
|
|
|
- Binding="{Binding color}"/>
|
|
|
- <DataGridTextColumn
|
|
|
- Header="Повреждения"
|
|
|
- Binding="{Binding defects}"/>
|
|
|
- <DataGridTextColumn
|
|
|
- Header="Дата СТО"
|
|
|
- Binding="{Binding dateOfLastSTO}"/>
|
|
|
- </DataGrid.Columns>
|
|
|
- </DataGrid>
|
|
|
+
|
|
|
+ <ListBox.ItemContainerStyle>
|
|
|
+ <Style
|
|
|
+ TargetType="ListBoxItem">
|
|
|
+ <Setter
|
|
|
+ Property="HorizontalContentAlignment"
|
|
|
+ Value="Stretch" />
|
|
|
+ </Style>
|
|
|
+ </ListBox.ItemContainerStyle>
|
|
|
+ <ListBox.ItemTemplate>
|
|
|
+ <DataTemplate>
|
|
|
+ <Border
|
|
|
+ BorderThickness="1"
|
|
|
+ BorderBrush="Black"
|
|
|
+ CornerRadius="5">
|
|
|
+ <Grid
|
|
|
+ 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 price}"/>
|
|
|
+
|
|
|
+ </StackPanel>
|
|
|
+ <TextBlock
|
|
|
+ Grid.Column="2"
|
|
|
+ Text="{Binding year}"/>
|
|
|
+
|
|
|
+ </Grid>
|
|
|
+ </Border>
|
|
|
+ </DataTemplate>
|
|
|
+ </ListBox.ItemTemplate>
|
|
|
+ </ListBox>
|
|
|
<StackPanel
|
|
|
Orientation="Vertical"
|
|
|
Grid.RowSpan="3"
|
|
@@ -648,9 +690,176 @@ ItemsSource="{Binding CarpriceList}">
|
|
|
</WrapPanel>
|
|
|
</Grid>
|
|
|
</Window>
|
|
|
-
|
|
|
```
|
|
|
***
|
|
|
**Вот что получилось**
|
|
|
***
|
|
|
-![](./img/qqq.png)
|
|
|
+![](./img/image.png)
|
|
|
+
|
|
|
+```
|
|
|
+<Window x:Class="WpfApp1.MainWindow"
|
|
|
+ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
|
|
+ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
|
|
+ xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
|
|
+ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
|
|
+ xmlns:local="clr-namespace:WpfApp1"
|
|
|
+ mc:Ignorable="d"
|
|
|
+ Title="Иванов Валера И-21" Height="450" Width="908">
|
|
|
+ <Window.Resources>
|
|
|
+ <BitmapImage
|
|
|
+ x:Key='defaultImage'
|
|
|
+ UriSource='./bin/Debug/net8.0-windows/img/net.jpg' />
|
|
|
+ </Window.Resources>
|
|
|
+ <Grid ShowGridLines="True">
|
|
|
+ <Grid.RowDefinitions>
|
|
|
+ <RowDefinition Height="auto"/>
|
|
|
+ <RowDefinition />
|
|
|
+ <RowDefinition Height="auto"/>
|
|
|
+ </Grid.RowDefinitions>
|
|
|
+ <Grid.ColumnDefinitions>
|
|
|
+ <ColumnDefinition Width="200"/>
|
|
|
+ <ColumnDefinition/>
|
|
|
+ </Grid.ColumnDefinitions>
|
|
|
+
|
|
|
+ <!-- лого -->
|
|
|
+ <Image
|
|
|
+ Source="./bin/Debug/net8.0-windows/img/net.jpg"
|
|
|
+ Grid.RowSpan="2" HorizontalAlignment="Right"/>
|
|
|
+ <ListBox
|
|
|
+ Grid.Row="1"
|
|
|
+ Grid.Column="1"
|
|
|
+ Background="White"
|
|
|
+ ItemsSource="{Binding CarList}"
|
|
|
+ ScrollViewer.HorizontalScrollBarVisibility="Disabled">
|
|
|
+
|
|
|
+ <ListBox.ItemsPanel>
|
|
|
+ <ItemsPanelTemplate>
|
|
|
+ <WrapPanel
|
|
|
+ HorizontalAlignment="Center" />
|
|
|
+ </ItemsPanelTemplate>
|
|
|
+ </ListBox.ItemsPanel>
|
|
|
+ <ListBox.ItemTemplate>
|
|
|
+ <DataTemplate>
|
|
|
+ <Border
|
|
|
+ BorderThickness="1"
|
|
|
+ BorderBrush="Black"
|
|
|
+ CornerRadius="5">
|
|
|
+ <Grid
|
|
|
+ Margin="10"
|
|
|
+ Width="200"
|
|
|
+ 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 price}"/>
|
|
|
+
|
|
|
+ </StackPanel>
|
|
|
+ <TextBlock
|
|
|
+ Grid.Column="2"
|
|
|
+ Text="{Binding year}"/>
|
|
|
+
|
|
|
+ </Grid>
|
|
|
+ </Border>
|
|
|
+ </DataTemplate>
|
|
|
+ </ListBox.ItemTemplate>
|
|
|
+ </ListBox>
|
|
|
+ <StackPanel
|
|
|
+ Orientation="Vertical"
|
|
|
+ Grid.RowSpan="3"
|
|
|
+ VerticalAlignment="Bottom">
|
|
|
+ <Button
|
|
|
+ x:Name="ExitButton"
|
|
|
+ Content="Выход"
|
|
|
+ Click="ExitButton_Click"
|
|
|
+ Height="50"/>
|
|
|
+ </StackPanel>
|
|
|
+
|
|
|
+
|
|
|
+ <WrapPanel
|
|
|
+ Orientation="Horizontal"
|
|
|
+ Grid.Column="1"
|
|
|
+ MinHeight="50">
|
|
|
+ <Label
|
|
|
+ Content="Поиск"
|
|
|
+ VerticalAlignment="Center"/>
|
|
|
+ <TextBox
|
|
|
+ Width="200"
|
|
|
+ VerticalAlignment="Center"
|
|
|
+ x:Name="SearchFilterTextBox"
|
|
|
+ KeyUp="SearchFilter_KeyUp"/>
|
|
|
+
|
|
|
+ <Label
|
|
|
+ Content="Название:"
|
|
|
+ VerticalAlignment="Center"/>
|
|
|
+
|
|
|
+ <ComboBox
|
|
|
+ Name="carnameFilterComboBox"
|
|
|
+ SelectionChanged="carnameFilterComboBox_SelectionChanged"
|
|
|
+ VerticalAlignment="Center"
|
|
|
+ MinWidth="100"
|
|
|
+ SelectedIndex="0"
|
|
|
+ ItemsSource="{Binding CarinfoList}">
|
|
|
+ <ComboBox.ItemTemplate>
|
|
|
+ <DataTemplate>
|
|
|
+ <Label
|
|
|
+ Content="{Binding title}"/>
|
|
|
+ </DataTemplate>
|
|
|
+ </ComboBox.ItemTemplate>
|
|
|
+ </ComboBox>
|
|
|
+ <Label
|
|
|
+Content="Цена:"
|
|
|
+VerticalAlignment="Center"/>
|
|
|
+
|
|
|
+ <ComboBox
|
|
|
+Name="carpriceFilterComboBox"
|
|
|
+SelectionChanged="carpriceFilterComboBox_SelectionChanged"
|
|
|
+VerticalAlignment="Center"
|
|
|
+MinWidth="100"
|
|
|
+SelectedIndex="0"
|
|
|
+ItemsSource="{Binding CarpriceList}">
|
|
|
+
|
|
|
+ <ComboBox.ItemTemplate>
|
|
|
+ <DataTemplate>
|
|
|
+ <Label
|
|
|
+ Content="{Binding title}"/>
|
|
|
+ </DataTemplate>
|
|
|
+ </ComboBox.ItemTemplate>
|
|
|
+ </ComboBox>
|
|
|
+ <Label
|
|
|
+ Content="Возраст:"
|
|
|
+ VerticalAlignment="Center"/>
|
|
|
+ <RadioButton
|
|
|
+ GroupName="Age"
|
|
|
+ Tag="1"
|
|
|
+ Content="по возрастанию"
|
|
|
+ IsChecked="True"
|
|
|
+ Checked="RadioButton_Checked"
|
|
|
+ VerticalAlignment="Center"/>
|
|
|
+ <RadioButton
|
|
|
+ GroupName="Age"
|
|
|
+ Tag="2"
|
|
|
+ Content="по убыванию"
|
|
|
+ Checked="RadioButton_Checked"
|
|
|
+ VerticalAlignment="Center"/>
|
|
|
+ </WrapPanel>
|
|
|
+ </Grid>
|
|
|
+</Window>
|
|
|
+```
|
|
|
+
|
|
|
+![](./img/image1.png)
|