<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:System="clr-namespace:System;assembly=mscorlib"
Title="MainWindow" Height="350" Width="525">
<Window.Resources>
<System:DateTime x:Key="d" >2012/7/8</System:DateTime>
</Window.Resources>
<StackPanel>
<ContentControl Content="{Binding}" DataContext="{StaticResource d}" />
<TextBlock Text="{Binding}" DataContext="{StaticResource d}"/>
</StackPanel>
</Window>
This code gives me the following window.

Strangely, the identical binding when applies to ContentControl only shows date part and when applies to TextBlock also shows time part.
I’m just curious to know the reason and ask whether it is possible to exchange the presentation, I mean TextBlock only shows date part and ContentControl shows both part.
Thank you.
For the
ContentControl, useContentStringFormat. For theTextBlock, use aBindingwith aStringFormat:In short, the difference comes down to the fact that a
ContentControlcan show any oldobjectas content (not just astring) whereasTextBlock.Textcan only be astring.