XAML绑定
public class Follower { <br> private List<Skill> skillList; <br> Dictionary< string , Item> itemList = new Dictionary< string , Item>(); <br><br> public List<Skill> SkillList { get { return this .skillList; } } <br> public Dictionary< string , Item> ItemList { get { return this .itemList; } } |
如上是追随者的结构。如下绑定主手装备到XAML上
<Border BorderThickness= "1" Height= "96" Canvas.Left= "149" Canvas.Top= "164" Width= "50" BorderBrush= "{Binding ItemList[mainhand].BorderBrush}" > <Border.Background> <ImageBrush ImageSource= "{Binding ItemList[mainhand].BorderBackGround}" /> </Border.Background> <Image Source= "{Binding ItemList[mainhand].ItemImage}" Height= "96" Canvas.Left= "596" Canvas.Top= "120" Width= "50" Margin= "0,0,0,0" /> </Border> |
注意的是代码中实际是ItemList["mainhand"].BorderBrush,而在XAML中,两个双引号是不能写的。
如果要绑定技能2到XAML上,如下,可以使用数字index。
<Border BorderThickness= "1" Height= "24" Canvas.Left= "40" Canvas.Top= "182" Width= "24" > <Border.Background> <ImageBrush ImageSource= "{Binding SkillList[2].SkillImage}" /> </Border.Background> </Border> |
而如果要绑定collections的层级结构,则使用/即可。如下是msdn中path的解释
- Use the Path property to specify the source value you want to bind to:
- In the simplest case, the Path property value is the name of the property of the source object to use for the binding, such as Path=PropertyName.
- Subproperties of a property can be specified by a syntax similar to that used in C#. For instance, the clause Path=ShoppingCart.Order sets the binding to the subproperty Order of the object or property ShoppingCart.
- To bind to an attached property, place parentheses around the attached property. For example, to bind to the attached property DockPanel.Dock, the syntax isPath=(DockPanel.Dock).
- Indexers of a property can be specified within square brackets following the property name where the indexer is applied. For instance, the clause Path=ShoppingCart[0] sets the binding to the index that corresponds to how your property's internal indexing handles the literal string "0". Multiple indexers are also supported.
- Indexers and subproperties can be mixed in a Path clause; for example, Path=ShoppingCart.ShippingInfo[MailingAddress,Street].
- Inside indexers you can have multiple indexer parameters separated by commas (,). The type of each parameter can be specified with parentheses. For example, you can have Path="[(sys:Int32)42,(sys:Int32)24]", where sys is mapped to the System namespace.
- When the source is a collection view, the current item can be specified with a slash (/). For example, the clause Path=/ sets the binding to the current item in the view.
- When the source is a collection, this syntax specifies the current item of the default collection view.
- Property names and slashes can be combined to traverse properties that are collections. For example, Path=/Offices/ManagerName specifies the current item of the source collection, which contains an Offices property that is also a collection. Its current item is an object that contains a ManagerName property. Optionally, a period (.) path can be used to bind to the current source. For example, Text="{Binding}" is equivalent to Text="{Binding Path=.}".
补充一下,WP8开发中,app bar的icon,要求很龌龊:透明、alpha、白色前景。
我在Mspaint中画不出来,不知道怎么搞透明背景。后来搞定的方式是,vs2012中打开sdk中带的icon,把原有的select/delete掉,然后画上我自己要求的文字。
代码如下,出现错误,不能operated在这个stream上
public static BitmapImage GetBitmapFromIsolatedFolderByName( string file) { BitmapImage image = new BitmapImage(); var stream = localFolder.OpenFile(cachePath+ "\\" +file, System.IO.FileMode.Open); image.SetSource(stream); stream.Close(); return image; } |
重点在于红色那一行,如果不close,那么第二次就会发生这个exception。令人发指的是,发生exception的时候,callstack都是reflection的东西,看不到真正的root cause。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· 展开说说关于C#中ORM框架的用法!
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?