public class BaseModel : INotifyPropertyChanged { protected voID ChangeProperty(string propname) { if (PropertyChanged != null) { PropertyChanged.Invoke(this,new PropertyChangedEventArgs(propname)); } } public event PropertyChangedEventHandler PropertyChanged; }@H_502_6@
3、TreeVIEw使用多层Model绑定时,可以使用HIErarchicalDataTemplate,然后设置ItemSource,在其中使用Item的MouseleftbuttonDown事件时,可以在HIErarchicalDataTemplate中的根元素上使用MouseleftbuttonDown事件来处理,然后根据这个根元素的TemplatedParent来取得TreeVIEwItem @H_502_6@代码如下:
<HIErarchicalDataTemplate ItemsSource="{Binding OcSubFolders}"> <GrID HorizontalAlignment="Stretch" VerticalAlignment="Stretch" MouseleftbuttonDown="GrID_MouseleftbuttonDown"> </GrID> </HIErarchicalDataTemplate>
private voID GrID_MouseleftbuttonDown(object sender,MousebuttonEventArgs e) { GrID Grd = sender as GrID; FolderModel folderCurrent = Grd.DataContext as FolderModel; folderCurrent.OcSubFolders = FolderHelper.GetSubFolders(folderCurrent.FolderPath); }@H_502_6@
@H_502_6@
<HIErarchicalDataTemplate ItemsSource="{Binding OcSubFolders}"> <!-- <HIErarchicalDataTemplate.ItemContainerStyle> <Style targettype="TreeVIEwItem"> <EventSetter Event="TreeVIEwItem.MouseleftbuttonDown" Handler="GrID_MouseleftbuttonDown" /> </Style> </HIErarchicalDataTemplate.ItemContainerStyle> --> <GrID HorizontalAlignment="Stretch" VerticalAlignment="Stretch" MouseleftbuttonDown="GrID_MouseleftbuttonDown"> <GrID.ColumnDeFinitions> <ColumnDeFinition /> <ColumnDeFinition /> </GrID.ColumnDeFinitions> <Image GrID.Column="0" WIDth="32" Height="32" Source="/Images/folder.png" /> <StackPanel GrID.Column="1"> <StackPanel OrIEntation="Horizontal"> <TextBlock Text="{Binding Foldername}" /> <TextBlock Text="(" /> <TextBlock Text="{Binding FolderSize,Converter={StaticResource sizeConverter}}" /> <TextBlock Text=")" /> </StackPanel> <StackPanel> <TextBlock Text="{Binding SubFolderCount,Converter={StaticResource ResourceKey=folderCountConverter}}" /> </StackPanel> </StackPanel> </GrID> </HIErarchicalDataTemplate>总结
以上是内存溢出为你收集整理的WPF/Silverlight 常见问题汇总(记录点滴)全部内容,希望文章能够帮你解决WPF/Silverlight 常见问题汇总(记录点滴)所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)