惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

有赞技术团队
有赞技术团队
Security Archives - TechRepublic
Security Archives - TechRepublic
大猫的无限游戏
大猫的无限游戏
The GitHub Blog
The GitHub Blog
Google DeepMind News
Google DeepMind News
Vercel News
Vercel News
U
Unit 42
L
LangChain Blog
M
MIT News - Artificial intelligence
S
SegmentFault 最新的问题
月光博客
月光博客
MongoDB | Blog
MongoDB | Blog
Jina AI
Jina AI
博客园 - 聂微东
H
Hackread – Cybersecurity News, Data Breaches, AI and More
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Recent Announcements
Recent Announcements
Engineering at Meta
Engineering at Meta
Hacker News - Newest:
Hacker News - Newest: "LLM"
V2EX - 技术
V2EX - 技术
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
阮一峰的网络日志
阮一峰的网络日志
F
Fortinet All Blogs
D
DataBreaches.Net
Hacker News: Ask HN
Hacker News: Ask HN
W
WeLiveSecurity
N
News | PayPal Newsroom
量子位
Help Net Security
Help Net Security
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
N
News and Events Feed by Topic
Webroot Blog
Webroot Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
人人都是产品经理
人人都是产品经理
S
Security @ Cisco Blogs
Y
Y Combinator Blog
H
Heimdal Security Blog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Stack Overflow Blog
Stack Overflow Blog
Attack and Defense Labs
Attack and Defense Labs
S
Secure Thoughts
P
Privacy International News Feed
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
SecWiki News
SecWiki News
Last Week in AI
Last Week in AI
AI
AI
Recorded Future
Recorded Future
C
Cyber Attacks, Cyber Crime and Cyber Security
Microsoft Security Blog
Microsoft Security Blog
P
Privacy & Cybersecurity Law Blog

博客园 - Eric Fine

Wii Party U 游戏简介 OracleParameter.UdtTypeName的值必须是全大写! VS2012调用64位IIS Express [Fix] Emulator Error: Could not load OpenGLES emulation library: Could not load DLL! [Fix] "Loading toolbox content from package Microsoft.VisualStudio.IDE.Toolbox.ControlInstaller.ToolboxInstallerPackage'{2C98B35-07DA-45F1-96A3-BE55D91C8D7A}'" 暗黑3 API 预览版 中兴光纤猫 F420 破解 [Fix] Blend 4 出现 Line:0 Position:0 错误 多维数组操作 诺基亚WP7手机 710/800一分钟完美越狱测试 三星WP7手机MANGO一分钟完美越狱 让WCF代替WSE访问需要明文UserName/Password验证的WebService 變形金剛塔防 Anti-TD Xeno Tactic 2 Medieval Rampage Mac OS X Leopard 10.5.5 安裝手记 (Dell D830) 将DataTable导出为Excel (XML Spreadsheet). SPGridView 研究笔记 Part 3 - 分组
Silverlight 4 Binding Cheatsheet [转]
Eric Fine · 2011-12-06 · via 博客园 - Eric Fine

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, Type targetType, object parameter, 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,Path=Text, Converter={StaticResource TextToColourConverter}, ConverterParameter=true}" />
<TextBlock Text="Test text" Foreground="{Binding ElementName=SomeTextBox,Path=Text, Converter={StaticResource TextToColourConverter}, 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 TotalAmount, 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.