wpf stringformat d

时间:2013-01-25 04:55:50

标签: wpf string-formatting

为什么显示日期和时间(而不仅仅是日期)?

<ListView Name="AttachmentsLB" Width="160" ItemsSource="{Binding Path=PicuAttachments}" >
    <ListView.View>
        <GridView>
            <GridViewColumn Header="Start" DisplayMemberBinding="{Binding StartDate}" Width="80">
                <GridViewColumn.CellTemplate>
                    <DataTemplate>
                        <TextBlock Text="{Binding Path=., StringFormat=d}" />
                    </DataTemplate>
                </GridViewColumn.CellTemplate>
            </GridViewColumn>
            <GridViewColumn Header="Finish" DisplayMemberBinding="{Binding FinishDate}" Width="80">
                <GridViewColumn.CellTemplate>
                    <DataTemplate>
                        <TextBlock Text="{Binding Path=., StringFormat=d}" />
                    </DataTemplate>
                </GridViewColumn.CellTemplate>
            </GridViewColumn>
        </GridView>
    </ListView.View>
</ListView>

我也尝试过StringFormat = {} {0:d}和StringFormat = \ {0:d \}但没有成功

2 个答案:

答案 0 :(得分:0)

错误绑定上的StringFormat问题

<GridViewColumn Header="Start" DisplayMemberBinding="{Binding StartDate, StringFormat=d}" Width="75">
    <GridViewColumn.CellTemplate>
        <DataTemplate>
            <TextBlock Text="{Binding}" />
        </DataTemplate>
    </GridViewColumn.CellTemplate>
</GridViewColumn>

答案 1 :(得分:0)

如何使用它?更改绑定中的StringFormat:

DisplayMemberBinding="{Binding Path=startDate, StringFormat='yyyy-MM-dd'}"