Updated: July 2008
Gets or sets a string that specifies how to format the binding if it displays the bound value as a string.
Namespace:
System.Windows.Data
Assembly:
PresentationFramework (in PresentationFramework.dll)
XMLNS for XAML: http://schemas.microsoft.com/winfx/2006/xaml/presentation, http://schemas.microsoft.com/netfx/2007/xaml/presentation
Visual Basic (Declaration)
Public Property StringFormat As String
Dim instance As BindingBase
Dim value As String
value = instance.StringFormat
instance.StringFormat = value
public string StringFormat { get; set; }
public:
property String^ StringFormat {
String^ get ();
void set (String^ value);
}
public function get StringFormat () : String
public function set StringFormat (value : String)
<object StringFormat="string" .../>
Property Value
Type:
System..::.StringA string that specifies how to format the binding if it displays the bound value as a string.
StringFormat can be a predefined, composite, or custom string format. For more information about string formats, see Formatting Types.
If you set the Converter and StringFormat properties, the converter is applied to the data value first, and then the StringFormat is applied.
When you set the StringFormat on a Binding to a composite string format, you can specify only one parameter.
When you use a MultiBinding, the StringFormat property applies only when it is set on the MultiBinding. The value of StringFormat that is set on any child Binding objects is ignored. The number of parameters in a composite string format cannot exceed the number of child Binding objects in the MultiBinding.
When you use a PriorityBinding, you can set the StringFormat on the PriorityBinding, on child binding objects, or both. If the StringFormat is set on the child binding that is applied, that value is used. If the StringFormat is not set on the child binding that is applied, the StringFormat of the PriorityBinding is applied if it is set.
The following example uses the StringFormat property to convert Price, which is a Double, to a string that represents a currency. For the entire sample, see Formatting a String on a Binding Sample.
<ListView ItemsSource="{StaticResource MyData}">
<ListView.View>
<GridView>
<GridViewColumn DisplayMemberBinding="{Binding Path=Description}"/>
<GridViewColumn DisplayMemberBinding="{Binding Path=Price, StringFormat=Now {0:c}!}"/>
</GridView>
</ListView.View>
</ListView>
The following example uses the StringFormat property on a MultiBinding to build a string that includes the Description and Price of each item in a ListBox. For the entire sample, see Formatting a String on a Binding Sample.
<ListBox ItemsSource="{StaticResource MyData}">
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock>
<TextBlock.Text>
<MultiBinding StringFormat="{}{0} -- Now only {1:C}!">
<Binding Path="Description"/>
<Binding Path="Price"/>
</MultiBinding>
</TextBlock.Text>
</TextBlock>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
.NET Framework
Supported in: 3.5 SP1, 3.0 SP2
Reference
Date | History | Reason |
|---|
July 2008
| Added topic for new member. |
SP1 feature change.
|