欧美性猛交XXXX免费看蜜桃,成人网18免费韩国,亚洲国产成人精品区综合,欧美日韩一区二区三区高清不卡,亚洲综合一区二区精品久久

打開(kāi)APP
userphoto
未登錄

開(kāi)通VIP,暢享免費電子書(shū)等14項超值服

開(kāi)通VIP
WPF Databinding----Collections
WPF(Windows Presentation Fundation) databinding功能能很好的顯示listbox, listview中的內容.在其中有四個(gè)要素:1.綁定目標(binding target), 2. 目標屬性(target property), 3.綁定的源數據( binding source), 4. 綁定的屬性,通過(guò)關(guān)鍵字Path來(lái)指定( a path to the source to use)如下圖:
數據綁定幾個(gè)必要做的事:
1. 實(shí)現 INotifyPorpertyChanged接口,
2.有屬性改變時(shí)通過(guò)PropertyChangedEventHandler來(lái)捕捉
3.ObservableCollection是INotifyPropertyChanged內建的實(shí)現數據綁定.
4.XAML文件中必需添加xmlns:<YourSpecifiedName>="clr-namespace:YourNameSpace"
好,讓我們來(lái)看一個(gè)具體的例子.創(chuàng )建一個(gè)WPF應用程序,采用C#來(lái)做.
文件 Data.cs:
using System;
using System.ComponentModel;
using System.Collections.ObjectModel;
namespace Collections
{
public class Person : INotifyPropertyChanged
{
//the person‘s attribute sex
private string name;
private string sex;
public event PropertyChangedEventHandler PropertyChanged;
//person constructor
public Person()
{
}
public Person(string named, string sexy)
{
this.name = named;
this.sex = sexy;
}
//person name attribute
public string Name
{
get { return name; }
set
{
this.name = ;
OnPropertyChanged("Name");
}
}
//person sex attribute
public string Sex
{
get { return sex; }
set
{
this.sex = ;
OnPropertyChanged("Sex");
}
}
//override the ToString method for dispaly Person‘s name
// if not override it, it will be displayed as "Collections.Person" but not person‘s name
public override string ToString()
{
return name.ToString();
}
//cacth up the property changed event
protected void OnPropertyChanged(string inputstring)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (handler != null)
{
handler(this,new PropertyChangedEventArgs(inputstring));
}
}
}
public class People : ObservableCollection<Person>
{
public People():base()
{
Add(new Person("Ekin", "Male"));
Add(new Person("Jack", "Male"));
Add(new Person("Jane", "Female"));
}
}
}
Windows1.xaml文件,注意XAML文件必需保持父子層嚴格的縮進(jìn).
<Window x:Class="Collections.Window1"
xmlns="
xmlns:x="
xmlns:Local="clr-namespace:Collections"        <!--this is we should add the XAML file-->
Title="Window1" Height="300" Width="300">
<Resources>
<Local:People x:Key="SomePerson"/>
<DataTemplate x:Key="DetailTemplate">
<!--define the display format-->
<Border Width="200" Height="50" Margin="20"
BorderBrush="Red" BorderThickness="1" Padding="8">
<Grid>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<TextBlock Grid.Row="0" Grid.Column="0" Text="Person‘s Name:"/>
<TextBlock Grid.Row="0" Grid.Column="1" Text="{Binding Path = Name}"/>
<TextBlock Grid.Row="1" Grid.Column="0" Text="Sex:"/>
<TextBlock Grid.Row="1" Grid.Column="1" Text="{Binding Path = Sex}"/>
</Grid>
</Border>
</DataTemplate>
</Resources>
<Grid>
<ListBox Margin="52,45,57,0" Name="listBox1" Height="53" VerticalAlignment="Top" ItemsSource="{Binding Source ={StaticResource SomePerson}}" IsSynchronizedWithCurrentItem="True" />
<ContentControl  Content="{Binding  Source = {StaticResource SomePerson}}"
ContentTemplate="{Binding Source = {StaticResourceDetailTemplate}}" />
<ContentControl Margin="0,119,84,65" Name="contentControl1"></ContentControl>
</Grid>
</Window>
在這里相對的綁定我都用相同的著(zhù)色標示出來(lái)了.
OK,這就搞定了.
打開(kāi)APP,閱讀全文并永久保存 查看更多類(lèi)似文章
猜你喜歡
類(lèi)似文章
操作HashTable
閑話(huà)WPF之十五(WPF的數據處理 [2])
yield關(guān)鍵字
Unity擴展讓枚舉視圖中變成多選框
(精華)2020年6月27日 C#類(lèi)庫 PostgreSqlHelper(Ado.net數據庫封裝)
無(wú)法將類(lèi)型為“System.Data.Common.DataRecordInternal”的對象強制轉換為類(lèi)型“System.Data.DataRowView”。
更多類(lèi)似文章 >>
生活服務(wù)
分享 收藏 導長(cháng)圖 關(guān)注 下載文章
綁定賬號成功
后續可登錄賬號暢享VIP特權!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服

欧美性猛交XXXX免费看蜜桃,成人网18免费韩国,亚洲国产成人精品区综合,欧美日韩一区二区三区高清不卡,亚洲综合一区二区精品久久