silverlight   发布时间:2022-05-03  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了Silverlight 4 Binding Cheatsheet大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

概述@H_616_4@ Path <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
Path
<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}" />

If the object in the DataContext has is another object with properties then you can bind to it's properties by using a fullstop.

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.

Converter

<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;
    }
}

Converter : Staticresource declared in resources. Converter is defined in codebehind and implements IValueConverter

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.

Numeric String Formats


 

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.


Indexed Bindings

<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>

You can bind to any collection that has an index (is IEnumerablE). If the collection is a Key/value collection such as Dictionary or Hash,then the item can be referenced by the item's key.

大佬总结

以上是大佬教程为你收集整理的Silverlight 4 Binding Cheatsheet全部内容,希望文章能够帮你解决Silverlight 4 Binding Cheatsheet所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。