c#


xaml conditional StringFormat


I would like to make a binding with a "conditional" price format.
More precisely, If another property is at true: display price without percentage, if it is at false, display price with percentage. Is there a way to handle this case with xaml or should I just make a string price property in my code-behind code?
You can use DataTrigger like this WPF DataBinding with an conditional expression. And for other formats of value you can use different Converters.
For example:
<UserControl.Resources>
<converters:ToPercentage x:Key="ToPercentage"/>
</UserControl.Resources>
<TextBox>
<TextBox.Style>
<Style TargetType="TextBox">
<Style.Triggers>
<DataTrigger Binding="{Binding Path=AnotherProperty}" Value="True">
<Setter Property="Text" Value="{Binding Path=Price}"/>
</DataTrigger>
<DataTrigger Binding="{Binding Path=AnotherProperty}" Value="False">
<Setter Property="Text" Value="{Binding Path=Price, Converter={StaticResource ToPercantage}}"/>
</DataTrigger>
</Style.Triggers>
</Style>
</TextBox.Style>
</TextBox>

Related Links

Huge performance hit for inlining sync method into async method
How to call multiple WCF methods in sequence without blocking the UI thread?
Problems with my threads array
find a file name knowing only the extension name
How to remove the <br> tag in my html string using HtmlAgilityPack in C#?
Generic function return value can not be specified creating generic methods
Converting string to DateTime [duplicate]
PayPal Recurring Payments Billing frequency
How to get all the possible 3 letter permutations? [duplicate]
C# Options to best consume C++ DLLs with 1000's of functions
Shapen raises IllegalStateException when attempting to convert java code
How convert a stored procedure result to a specific type
Ray Intersection doesn't work correctly
How to detect that TFS Project Source Code has been modified
What happens when a connection is terminated in the middle of a remote call on a .NET remoting server?
XNA- Looking for an algorithm

Categories

HOME
kendo-ui
network-programming
wifi
phantomjs
bigtable
stdout
hiveql
overrides
mediarecorder
sequence
doctrine2
samsung-gear-s2
sahi
wowza
fetch
suitecrm
unreal-engine4
derby
simd
web-parts
gpo
descriptor
tcpdf
functional-dependencies
policy
ps
jira-zephyr
continuous-fourier
drombler-fx
osgi-bundle
r-factor
xlib
openoffice-impress
multilanguage
machine-code
matlab-compiler
cache-control
respect-validation
lighting
form-fields
word-wrap
ui-grid
fisheye
icu
electron-packager
flume-ng
result
gradlew
denodo
noise
multivalue
extjs3
gige-sdk
timefield
foreground
mate-desktop
scriptengine
vga
android-xmlpullparser
php-java-bridge
mrunit
angular-i18n
python-rq
jmap
apache2-module
videoview
persian
personality-insights
jsoncpp
hexagonal-tiles
vensim
log-analysis
httpmodule
gmaps4jsf
mri
system.net
step
facebook-java-api
ojb
nsnumber
backbone-views
http-compression
coinbase-php
rfc822
webpage-screenshot
blackberry-eclipse-plugin
bash4
maven-eclipse-plugin
cherokee
soapexception
file-processing
excellibrary
lgpl
versions
datadude

Resources

Encrypt Message