对不起,不清楚的问题:我不知道如何写我想问的,但我的代码帮助我清除它:
VehicleWidget.xaml
<local:ParkingWidget x:Class="VehiclesWidget"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:Widgets" Loaded="ParkingWidget_Loaded" mc:Ignorable="d" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" Height="65" Width="420">
<Grid Height="61" Width="411">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="5"/> <!--0-->
<ColumnDefinition Width="Auto"/> <!--1-->
<ColumnDefinition Width="Auto"/> <!--2-->
<ColumnDefinition Width="298"/>
<ColumnDefinition Width="0*" />
<ColumnDefinition Width="38*" />
<!--3-->
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="5"/> <!--0-->
<RowDefinition Height="Auto"/> <!--1-->
<RowDefinition Height="5"/> <!--2-->
<RowDefinition Height="Auto"/> <!--3-->
<RowDefinition Height="5"/> <!--4-->
</Grid.RowDefinitions>
<Label
Content="Vehicles"
Grid.Column="1" Grid.Row="1"/>
<Button
Name="btnRefresh"
Grid.Column="2" Grid.Row="1"
Content="Refresh"
Width="98"
HorizontalAlignment="Right"
Click="btnRefresh_Click" Grid.ColumnSpan="2" Margin="0,2,257,2">
</Button>
<DataGrid
Name="VehiclesDataGrid"
AutoGenerateColumns="False"
IsReadOnly="True"
Grid.Column="1" Grid.Row="3" Grid.ColumnSpan="3" FontFamily="Arial" Margin="0,0,3,0">
<DataGrid.Columns>
<DataGridTextColumn Header="Time" x:Name="timeColumn" Binding="{Binding Path=Time}" />
<DataGridTextColumn Header="TicketId" x:Name="tickedIdColumn" Binding="{Binding Path=TicketId}" />
<DataGridTextColumn Header="LPN" x:Name="lpnColumn" Binding="{Binding Path=LPN}" Visibility="Hidden" />
<DataGridHyperlinkColumn Header="Picture" x:Name="pictureColumn" Binding="{Binding Path=TicketId}" Visibility="Hidden">
<DataGridHyperlinkColumn.ElementStyle>
<Style>
<EventSetter Event="Hyperlink.Click" Handler="Hyperlink_Click"/>
</Style>
</DataGridHyperlinkColumn.ElementStyle>
</DataGridHyperlinkColumn>
<DataGridTextColumn Header="Class" x:Name="classColumn" Binding="{Binding Path=HeightClassification}" />
<DataGridTextColumn Header="Weight" x:Name="weightColumn" Binding="{Binding Path=Weight}" />
<DataGridTextColumn Header="Orientation" x:Name="orientationColumn" Binding="{Binding Path=Orientation.Degrees}" />
<DataGridTextColumn Header="Piston1" x:Name="piston1Column" Binding="{Binding Path=Piston1}" />
<DataGridTextColumn Header="Piston2" x:Name="piston2Column" Binding="{Binding Path=Piston2}" />
<DataGridTextColumn Header="Location" x:Name="locationColumn" Binding="{Binding Path=Location}" />
</DataGrid.Columns>
</DataGrid>
</Grid>
在“VehicleWidget.xaml.cs”中,我有“列出车辆”,在“车辆”类中,我有以下属性:Piston1、Piston2、尺寸、LPN,当然还有重量
以下行,将列添加到网格并将其命名为“权重”并绑定到权重。
<DataGridTextColumn Header="Weight" x:Name="weightColumn" Binding="{Binding Path=Weight}" />
绑定如何知道选择哪个对象,获取它的属性?
我问这个问题是因为我想绑定不同对象的属性(不是像本例中那样的 Vehicle,而是继承自 Vehicle 的 NewVehicle)。