在WPF

时间:2016-09-02 08:45:11

标签: c# wpf listview binding

我将ListView上的ItemsSource设置为类Mail。我希望有一个列与其他类的属性。如何将该列绑定到其他类?我检查了其他答案,但没有找到合适的答案。

而且XAML正在学习,所以代码隐藏是WPF中最常用的。

代码:

public class Mail
{
    [Key]
    public int IDMail { get; set; }
    public string prop1{ get; set; }
    public string prop2 { get; set; }
    public DateTime prop3{ get; set; }
    public Sender senderID{ get; set; }      
}

public class Sender
{
    [Key]
    public int IDSender { get; set; }
    public string propSender1{ get; set; }
    public string propSender2{ get; set; }  
}

XAML:

 <ListView x:Name="listView_knjizenaPosta" Background="#FFDEDEDE" HorizontalContentAlignment="Center"   HorizontalAlignment="Center" Height="293" Margin="0,69,0,260" VerticalAlignment="Center" Width="1018" FontSize="16" SelectionChanged="listView_knjizenaPosta_SelectionChanged" FontFamily="Verdana" MouseDoubleClick="listView_knjizenaPosta_MouseDoubleClick">
            <ListView.ItemContainerStyle>
                <Style TargetType="{x:Type ListViewItem}">
                    <Setter Property="HorizontalContentAlignment" Value="Center" />
                </Style>
            </ListView.ItemContainerStyle>
            <ListView.View>
                <GridView>

                    <GridViewColumn Header="ID" Width="50" DisplayMemberBinding="{Binding IDMail}"/>
                    <GridViewColumn Header="Prop1" Width="250" DisplayMemberBinding="{Binding prop1}" />
                    <GridViewColumn Header="Prop3" Width="185" DisplayMemberBinding="{Binding prop3, StringFormat=dd.MM.yyyy HH:mm:ss}" />                       
                    <GridViewColumn Header="PropSender2" Width="250" DisplayMemberBinding="{Binding WHAT GOES HERE?}" />

                </GridView>
            </ListView.View>
        </ListView>

0 个答案:

没有答案