stringformat

wpf image source: "format" binding (-> filename) with stringformat

i've got a INotifyPropertyChanged-abled class and thought it would be a good idea to use: <Image Source="{Binding myfilename, StringFormat='FixedPath/{0}.png'}" /> so whenever i would change myfilename in source, i'd get the corresponding image in my wpf gui. it compiles. but in the console i get the error that a TargetDefaultValueC...

Avoiding resource (localizable string) duplication with String.Format

I'm working on a application (.NET, but not relevant) where there is large potential for resource/string duplication - most of these strings are simple like: Volume: 33 Volume: 33 (dB) Volume 33 dB Volume (dB) Command - Volume: 33 (dB) where X, Y and unit are the same. Should I define a new resource for each of the string or is it ...

WPF StringFormat={}{0:N} Error "Expected '"

I'm getting an error in VS 2008 SP1 with WPF using the stringformat binding, is there an inherent problem with wpf in vs 2008? Error 1 Expected ' ConstituentCrossrateGridControl.xaml 70 141 PriceViewWpfLibrary ...

WPF Binding and Dynamically Assigning StringFormat Property

I have a form that is generated based on several DataTemplate elements. One of the DataTemplate elements creates a TextBox out of a class that looks like this: public class MyTextBoxClass { public object Value { get;set;} //other properties left out for brevity's sake public string FormatString { get;set;} } I need a way to "...

WPF TextBox StringFormat not working with PropertyChanged

I have a problem. I need to have double formatted values in all TextBoxes. When you type something into this, after lost focus it will be formatted. <TextBox Text="{Binding ABC, StringFormat='{}{0:N}'}" /> Problem arises when you add this UpdateSourceTrigger with propertychanged. Then it will never be formatted. <TextBox Text="{Bi...

WPF binding StringFormat syntax

How can I format a decimal value conditionally in a WPF window? Value should be rounded to a whole number (Ex: 1,234) When the value is 0.00, it should display as a single zero. (Ex: 0) Currently I use bellow mark up to format the decimal value, but it displays 00 when the value is 0.00. Please help. <TextBlock Grid.Column="6" Paddi...

Problem with UpdateSourceTrigger=PropertyChanged and StringFormat in WPF

Hi, I have a text box in my application which is data bound to a decimal field in my class and the binding mode is two way. I am using StringFormat={0:c} for currency formatting. This works fine as long as I don't touch 'UpdateSourceTrigger'. If I set UpdateSourceTrigger=PropertyChanged , It stops formatting the text that I am enterin...

String format in java?

Input String: 115.0000 Output String should be like: 115.00 i used this code: String.format("%.2f","115.0000"); i got IllegalArgumentException. What can i do now? ...

WPF Image Source binding with StringFormat

Hello, I'm new to WPF and MVVM (started this week experimenting with it) and trying to bind image resources at runtime. The items I'm trying to display contain an enumerate property that indicates the type or state of the item: public class TraceEvent { /// <summary> /// Gets or sets the type of the event. /// </summary> ...

Precision specifier as parameter like printf but in String.Format

Using printf i could specify the precision value as an extra parameter using *. Does the same functionality exist in the C# String.Format? edit: For example: Console.WriteLine("{0:D*}",1,4); // Outputs 0001; ...

WPF: How to bind a numeric property to DataGridTextColumn?

I thought it should be a simple thing for WPF, but I can't make it work... I have an int property (Divisions) on my class and I want to bind it to a DataGrid column. <DataGrid AutoGenerateColumns="False"> <DataGrid.Columns> <DataGridTextColumn Header="Number of Divisions" Binding="{Binding Path=Divisions, StringFormat={...

How to hide stringformat if data is null

Hi..How to hide a stringformat when data is not present.Consider this sample <TextBlock Text="{Binding Amount, StringFormat=Total: {0:C}}" /> in this case if Amount is null,Then it will show just Total:.How to hide this if Amount is null or empty ...

WPF: Textbox Binding with StringFormat={}{0:F2}. Don't show zero's.

I am binding an object to a TextBox with the following XAML: <TextBox Name="MyTextBox" Text="{Binding Path=MyValue, Mode=TwoWay, StringFormat={}{0:F2}}" /> Naturally when I bind a new object (which values are all still zero) the Text property is set to 0.00. I have several of these TextBoxes, which makes it tedious to delete every valu...

String.Format in C# not returning modified int value

I am tring to return an int value with comma seperators within the value. 12345 would be returned as 12,345 The follwing code works: int myInt = 1234567; MessageBox.Show(string.Format("My number is {0}", myInt.ToString("#,#"))); 12,345 is displayed as expected. While the following code does no work, but from what I am reading, shou...

Using Multibinding.StringFormat in codebehind

I have this application that has dynamic language switching built in. Based on the selected Culture, strings throughout the application will change. Translated strings and their original values come out of resource files. I use bindings to attach the resource values to buttons, labels, etc. Most of this binding occurs in the code beh...

wpf - binding stringformat on label using string literal

I've binded the tooltip of a slider control to it's Value property and i'm trying to use StringFormat to make it display "Current Value {0} of 10" where the {0} is the Value property. Below is one of the various things I tried when trying to figure this out. <Slider.ToolTip> <Label> ...

Sizing image to text in the image with C# System.Drawing / Drawstring

I want to take a string, and a specified font, and create a graphic image that contains that text in box, where the box resizes to the text. I got the code below working, but it sizes the box before doing anything else. Is there some way to resize the image to fit the text (I probably need to add a small border of a few pixels). A...

Binding StringFormat

I have a collection of textblocks that I'm going to be showing and I'm needing the text of each textblock to be displayed differently. I'm currently saving the format string in the tag property and I'm needing to display the text in this format. How do I bind the StringFormat section? Something like the section below: <TextBlock Tag="{...