锘??xml version="1.0" encoding="utf-8" standalone="yes"?>国产亚洲精品91在线,亚洲一区二区五区,黄色小视频在线播放http://www.aygfsteel.com/zxj8314/archive/2007/02/05/98100.htmlzilongzilongMon, 05 Feb 2007 11:49:00 GMThttp://www.aygfsteel.com/zxj8314/archive/2007/02/05/98100.htmlhttp://www.aygfsteel.com/zxj8314/comments/98100.htmlhttp://www.aygfsteel.com/zxj8314/archive/2007/02/05/98100.html#Feedback0http://www.aygfsteel.com/zxj8314/comments/commentRss/98100.htmlhttp://www.aygfsteel.com/zxj8314/services/trackbacks/98100.htmlhttp://www.beacosta.com/Archive/2005_09_01_bcosta_archive.html聽
聽聽1.緇戝畾鏂瑰紡錛?br />聽聽聽聽聽聽 1錛塖ource/Data Context錛?br />聽聽聽聽聽聽聽聽聽聽聽聽<Window.Resources>
聽聽聽聽聽聽聽聽聽聽<local:GreekGod Name="Zeus" Description="Supreme God of聽聽聽聽the聽聽聽聽Olympians"聽聽聽聽聽聽聽RomanName="Jupiter" x:Key="zeus"/>
聽聽聽聽<local:GreekGod Name="Poseidon" Description="God of the sea, earthquakes and horses"聽聽聽聽RomanName="Neptune" x:Key="poseidon"/>
</Window.Resources>

<StackPanel DataContext="{StaticResource poseidon}">
聽聽聽聽<TextBlock TextContent="{Binding Source={StaticResource zeus}, Path=Name}"/>
聽聽聽聽<TextBlock TextContent="{Binding Path=Description}"/>
聽聽聽聽<TextBlock TextContent="{Binding Path=RomanName}"/>
</StackPanel>
Data Context鍏佽鍏冪礌浠庡畠鐨勭埗鍏冪礌緇ф壙鏁版嵁緇戝畾鐨勬暟鎹簮銆?br />Source鏍囪鏄懼紡鎸囧畾鏁版嵁婧愩?br />涓鑸儏鍐典笅錛岀粦瀹氭簮瀵硅薄涓涓睘鎬ф椂鐢―ata Context錛岀粦瀹氭簮瀵硅薄涓崟涓睘鎬ф椂鐢?span>Source銆?/span>聽鍦ㄧ粦瀹氭椂聽Source鍜孌ata Context鏁堟灉涓鏍鳳紝鍙槸Source鐨勪紭鍏堢駭姣?/span>Data Context聽楂樸偮犲鏋滅粦瀹氬璞℃槸涓涓獂ml錛屽垯{Binding}涓睘鎬х敤xpath鏉ユ寚瀹氬簲璇ヤ嬌鐢?XML 鏂囨。涓殑鍝釜闆嗗悎鏉ュ~鍏呫偮犅犅?br />2錛塃lementName錛?br />3錛?font face="Verdana">RelativeSource錛?br />2.{binding}
聽聽聽bingding鏈塻ource鍜宲ath灞炴э紝鍏朵腑source灞炴ф寚瀹氱粦瀹氱殑鍏蜂綋鏁版嵁瀵硅薄錛宲ath鎸囧畾璇ュ璞$殑鐗瑰畾灞炴с傚綋閫昏緫鏍?wèi)涓湁Data Context錛屽彲浠ヤ笉鐢ㄨ瀹歜inding涓璼ource灞炴э紱褰揵inding涓病鏈夎瀹歱ath灞炴ц〃鏄庣粦瀹氭暣涓璞°?br /><Window.Resources>
聽聽聽聽<local:GreekGod Name="Zeus" Description="Supreme God of the Olympians" RomanName="Jupiter" x:Key="zeus"/>
</Window.Resources>

<Border DataContext="{StaticResource zeus}">
聽聽聽聽<ContentControl Content="{Binding}"/>
</Border>


聽聽 濡傛灉瑕佸皢鏌愪竴鍏冪礌涓庡璞$殑澶氫釜灞炴х粦瀹氭椂錛?/font>ContentControl 涓嶇煡閬撳浣旼reekGod 鐨勪俊鎭傝繖鏃惰鐢ㄥ埌DataTemplate錛屽畠鐨勪綔鐢ㄦ槸鎸囧畾鏁版嵁鏄劇ず褰㈠紡銆?br />聽聽聽<Window.Resources>
聽聽聽聽<local:GreekGod Name="Zeus" Description="Supreme God of the Olympians" RomanName="Jupiter" x:Key="zeus"/>

聽聽聽聽<DataTemplate x:Key="contentTemplate">
聽聽聽聽聽聽聽聽<DockPanel>
聽聽聽聽聽聽聽聽聽聽聽聽<TextBlock Foreground="RoyalBlue" TextContent="{Binding Path=Name}" />
聽聽聽聽聽聽聽聽聽聽聽聽<TextBlock TextContent=":" Margin="0,0,5,0" />
聽聽聽聽聽聽聽聽聽聽聽聽<TextBlock Foreground="Silver" TextContent="{Binding Path=Description}" />
聽聽聽聽聽聽聽聽</DockPanel>
聽聽聽聽</DataTemplate>
</Window.Resources>

<Border DataContext="{StaticResource zeus}">
聽聽聽聽<ContentControl Content="{Binding}" ContentTemplate="{StaticResource contentTemplate}"/>
</Border>


娉ㄦ剰錛?font face="Courier" color="#6666cc">DataTemplate涓殑{binding}娌℃湁source灞炴э紝榪欐槸鍥犱負(fù)鑷姩鍦板皢Data Context璁句負(fù)鏁版嵁瀵硅薄緇戝畾鏂瑰紡銆偮?/font>
3銆?font face="Courier" color="#6666cc">get ListItem from a data bound Listbox
xaml:
聽聽聽 <Window.Resources>
聽聽聽聽<local:GreekGods x:Key="greekGods"/>

聽聽聽聽<DataTemplate x:Key="itemTemplate">
聽聽聽聽聽聽聽聽<TextBlock Text="{Binding Path=Name}" />
聽聽聽聽</DataTemplate>
</Window.Resources>

<ListBox ItemsSource="{StaticResource greekGods}" ItemTemplate="{StaticResource itemTemplate}" Name="listBox"/>

listBox鐨処temSource鏈変竴涓?font face="Verdana">IEnumerable鎺ュ彛錛屾槸浣犳兂瑕佹樉紺虹殑items鍒楄〃
Itemtemplate灞炴ф寚瀹氱敤鏉ユ帶鍒舵暟鎹樉紺虹殑datatemplate銆?br />
c#:
GreekGod greekGod = (GreekGod)(listBox.Items[0]);//緇戝畾鐨勬暟鎹璞★紱
ListBoxItem lbi1 = (ListBoxItem)(listBox.ItemContainerGenerator.ContainerFromIndex(0));//榪斿洖ListBoxItem錛?/font>
ListBoxItem lbi2 = (ListBoxItem)(listBox.ItemContainerGenerator.ContainerFromIndex(listBox.Items.CurrentItem));
涓轟簡淇濊瘉閫変腑欏逛笌褰撳墠欏瑰悓姝ワ紝璁懼畾
IsSynchronizedWithCurrentItem= "true".

4.get a ComboBoxItem from a data bound ComboBox
涓巐istbox鐩鎬技錛?br />
Window.Resources>
聽聽聽聽<local:GreekGods x:Key="greekGods"/>

聽聽聽聽<DataTemplate x:Key="itemTemplate">
聽聽聽聽聽聽聽聽<TextBlock Text="{Binding Path=Name}" />
聽聽聽聽</DataTemplate>
</Window.Resources>

<ComboBox ItemsSource="{StaticResource greekGods}" ItemTemplate="{StaticResource itemTemplate}" Width="200" Name="comboBox"/>


c#:
GreekGod greekGod = (GreekGod)(comboBox.Items[0]);
comboBox.IsDropDownOpen = true;
ComboBoxItem cbi1 = (ComboBoxItem)(comboBox.ItemContainerGenerator.ContainerFromIndex(0));
ComboBoxItem cbi2 = (ComboBoxItem)(comboBox.ItemContainerGenerator.ContainerFromItem(comboBox.Items.CurrentItem));
comboBox.IsDropDownOpen = false;
娉ㄦ剰錛?br />璋冪敤ContainerFromIndex涔嬪墠瑕佸厛鎵撳紑緇勫悎妗嗐?font face="Courier" color="#6666cc">comboBox.IsDropDownOpen = true;


zilong 2007-02-05 19:49 鍙戣〃璇勮
]]>
主站蜘蛛池模板: 临湘市| 垫江县| 沙洋县| 额尔古纳市| 改则县| 红河县| 宝丰县| 阿勒泰市| 金坛市| 济阳县| 大邑县| 山西省| 烟台市| 湖北省| 台北县| 沈阳市| 阿拉善右旗| 蒙城县| 庄河市| 乌苏市| 阜康市| 洪雅县| 新野县| 东安县| 喀喇沁旗| 河西区| 潮安县| 西青区| 仁寿县| 岢岚县| 健康| 海南省| 陵川县| 名山县| 阿鲁科尔沁旗| 贵南县| 巴林左旗| 监利县| 邹平县| 射洪县| 施秉县|