Can we do this in xaml using string format at all? I do not want to use any C# as I have no access to that.
For example:
<sap:Parameter x:Key="DescriptionForDisplay">
<sap:Parameter.Value>
<MultiBinding Converter="{StaticResource DescriptionConverter}" ConverterParameter="/">
<Binding Source="{StaticResource aDataSource}" Path="Properties[ID].Value"/>
<Binding Source="{StaticResource aDataSource}" Path="Properties[Description].Value"/>
</MultiBinding>
</sap:Parameter.Value>
</sap:Parameter>
Would give something like:
1234\My Description
And I would love to do the inverse of this so I could have one parameter/static resource set as '1234' and another parameter/static resource be 'My Description'
You could use a StringFormat like this:
<sap:Parameter x:Key="DescriptionForDisplay">
<sap:Parameter.Value>
<MultiBinding StringFormat="{}{0}\{1}">
<Binding Source="{StaticResource aDataSource}" Path="Properties[ID].Value"/>
<Binding Source="{StaticResource aDataSource}" Path="Properties[Description].Value"/>
</MultiBinding>
</sap:Parameter.Value>
</sap:Parameter>
This would display the Id\Description without the use of any converter.
Related
Hi I am trying to achieve a binding like this:
<ComboBoxItem Style="{StaticResource ComboBoxItemStyle2}">
<ComboBoxItem.Content>
<MultiBinding StringFormat=" {}{0} {1}">
<Binding Path="Value" Source="{StaticResource Name}" />
<Binding Path="Name" Source="{StaticResource Person}" />
</MultiBinding>
</ComboBoxItem.Content>
</ComboBoxItem>
Where "Name" is a localized string and "Value" is used to get it's localized string.
for some reason this doesn't seems to work. I am getting empty string.
This might help you: String format using MultiBinding?
Taken from that post:
You are trying to bind a string to an object. But StringFormat requires its target to be a string type. Try putting a TextBlock in your content and bind your data to it.
Also put "" around Name.
Following is the corrected code:
<ComboBoxItem Style="{StaticResource ComboBoxItemStyle2}">
<TextBlock>
<TextBlock.Text>
<MultiBinding StringFormat="{}{0} {1}">
<Binding Path="Value" Source="{StaticResource Name}" />
<Binding Path="Name" Source="{StaticResource Person}" />
</MultiBinding>
</TextBlock.Text>
</TextBlock>
</ComboBoxItem>
I need to fix two things:
Keep the content as TextBlock and do binding of text there.
Removed extra spacing from StringFormat i.e. " {}{0} {1}" ==> "{}{0} {1}".
You Can see this link i wish be helpful
https://social.msdn.microsoft.com/Forums/vstudio/en-US/32b81578-b201-4927-bdc2-ebb9a42ae303/comboboxdisplaymemberpath-and-multibinding
So I have this XAML:
<TextBlock.Text>
<MultiBinding StringFormat="SomeText: {0}
SomeOtherText: {1}">
<Binding Path="SomeBoundVar" />
<Binding Path="AnotherBoundVar" StringFormat="{}{0:N2}" />
</MultiBinding>
</TextBlock.Text>
And I'd like to add a thousand separator to the 2nd binding (the StringFormat as above doesn't work).
How can I do that ? Or do I have to use a converter ?
I had a same kind of issue and following is the way I fixed.
<TextBlock>
<TextBlock.Text>
<MultiBinding StringFormat="{} Balance {0} : {1:##,#0.00}">
<Binding Path="Currency"/>
<Binding Path="Balance"/>
</MultiBinding>
</TextBlock.Text>
</TextBlock>
Sample Result
Balance AED : 2,456.45
I cannot for the life of me get this to work. I need to display hh:mm from a pair of timespan objects in a textblock and it is just not working. This is what I have so far:
<TextBlock>
<TextBlock.Text>
<MultiBinding StringFormat="{}From {0:hh\\:mm} to {1:hh\\:mm}">
<Binding Path="StartTime"/>
<Binding Path="EndTime"/>
</MultiBinding>
</TextBlock.Text>
</TextBlock>
The text block shows up blank. I've also tried the following with the same results:
<TextBlock>
<TextBlock.Text>
<MultiBinding StringFormat="{}From {0} to {1}">
<Binding Path="StartTime" StringFormat="hh\\:mm"/>
<Binding Path="EndTime" StringFormat="hh\\:mm"/>
</MultiBinding>
</TextBlock.Text>
</TextBlock>
If I have the string format as hust "hh" then I get just the hours, so I suppose I could build it out of 4 pieces but that just does not feel right. Any help is appreciated.
Using hh':'mm in the format string seems to work:
<TextBlock>
<TextBlock.Text>
<MultiBinding StringFormat="{}From {0:hh':'mm} to {1:hh':'mm}">
<Binding Path="StartTime"/>
<Binding Path="EndTime"/>
</MultiBinding>
</TextBlock.Text>
</TextBlock>
Also, this only works in .NET 4
I want to bind one property to multiple sources. My reason for this are things like this:
midpoint=point2.X - point1.X; //depends on two sources!
How could this be realised? As far as I know it's not directly possible out-of-the-box?
I believe what you are looking for is a MultiBinding.
From the MSDN documentation:
<TextBlock Name="textBox2" DataContext="{StaticResource NameListData}">
<TextBlock.Text>
<MultiBinding Converter="{StaticResource myNameConverter}"
ConverterParameter="FormatLastFirst">
<Binding Path="FirstName"/>
<Binding Path="LastName"/>
</MultiBinding>
</TextBlock.Text>
</TextBlock>
So here is my TextBlock:
<TextBlock Text="1 Projects / 1 Issues"></TextBlock>
Using data binding I want replace 1 and 2 with {Binding Path=OpenProjects} and {Binding Path=OpenIssues}. What is the best way to do this?
P.S. I am not married to TextBlock.
<TextBlock>
<TextBlock.Text>
<MultiBinding StringFormat="{}{0} Projects / {1} Issues">
<Binding Path="OpenProjects"/>
<Binding Path="OpenIssues"/>
</MultiBinding>
</TextBlock.Text>
</TextBlock>
You should look into string format