大佬教程收集整理的这篇文章主要介绍了Silverlight 4 Binding Cheatsheet,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
<TextBlock Text="{Binding Path=PropertyNamE}" /> <TextBlock Text="{Binding PropertyNamE}" />
Path : Name of the property on the object in the Datacontext of the page. The Path keyword is optional. The two lines above are functionally identical.
<TextBlock Text="{Binding Path=Instance.PropertyNamE}" />
ElementName
<TextBox x:Name="SomeTextBox" /> <TextBlock Text="{Binding ElementName=SomeTextBox,Path=Text}" />
ElementName : Specifies another element in the view tree to bind to. Path : The property on the source element to bind from.
<UserControl.resources> <BindingsProject:TextToColourConverter x:Key="TextToColourConverter" /> </UserControl.resources> <Grid x:Name="LayoutRoot"> <StackPanel> <TextBox x:Name="SomeTextBox" /> <TextBlock Text="{Binding ElementName=SomeTextBox,Path=Text}" /> <TextBlock Text="Test text" Foreground="{Binding ElementName=SomeTextBox,Path=Text,Converter={Staticresource TextToColourConverter}}" /> </StackPanel> </Grid>
public class TextToColourConverter: IValueConverter { public object Convert(object value,Type targetType,object parameter,CultureInfo culturE) { return someConvertedValue; } public object ConvertBACk(object value,CultureInfo culturE) { return someConvertedBACkValue; } }
ConverterParameter
<TextBlock Text="Test text" Foreground="{Binding ElementName=SomeTextBox,Converter={Staticresource TextToColourConverter},ConverterParameter=truE}" /> <TextBlock Text="Test text" Foreground="{Binding ElementName=SomeTextBox,ConverterParameter='Blue'}" />
String parameters can be passed to the value converter. Unfortunately you can not bind to the ConverterParameter.
String Format
<TextBlock Text="{Binding Path=TimeWorked,StringFormat=hh\\:mm}" /> <TextBlock Text="{Binding Path=TimeWorked,StringFormat='h\\:mm'}" /> <TextBlock Text="{Binding Path=StartDate,StringFormat=D}" /> <TextBlock Text="{Binding Path=StartDate,StringFormat='MMM dd,yyyy'}" /> <TextBlock Text="{Binding Path=StartDate,StringFormat=MMM\ dd\,\ yyyy}" /> <TextBlock Text="{Binding Path=StartDate,StringFormat=yyyy-MM-dD}" />
Use apostrophes to enclose String formats with special characters,or use \ to escape the special character.
Null Value
<TextBlock Text="{Binding @R_219_10586@lamount,TargetNullValue=0}" />
If the value from the bound property is null then it will be replaced with the TargetNullValue.
<StackPanel> <TextBlock Text="{Binding Path=SimpleProp1}" /> <TextBox Text="{Binding Path=ComplexProp[0].SimpleSubProp,Mode=TwoWay}" Width="200" Height="60"/> <TextBox Text="{Binding Path=DictionaryCollection[mineral],Mode=TwoWay}" /> </StackPanel>
以上是大佬教程为你收集整理的Silverlight 4 Binding Cheatsheet全部内容,希望文章能够帮你解决Silverlight 4 Binding Cheatsheet所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。