ممنونم از پاسخ گویی تون.
من پروژه رو نوشتم ولی برام همه رو دو نه کدونه در یه سطح میاره.
کدهامو می ذارم یه نگاه اگه میشه بندازید :
مدل hesabcoding:
public class HesabCoding : NotifyPropertyChangedHelper, IDataErrorInfo
{
private int id;
private string title;
private string fullTitle;
private string hesabCode;
private string fullHesabCode;
private byte hesabStructure_FK;
private string hesabStructure;
private byte hesabEntity_FK;
private string hesabEntity;
private short hesabGroup_FK;
private string hesabGroup;
private int parentId;
private bool isFinal;
private bool active;
private bool isAddByUser;
private string insertDateTime;
private string insertUser;
private string updateDateTime;
private string updateUser;
//ObservableCollection<HesabCoding> _children = new ObservableCollection<HesabCoding>();
//public ObservableCollection<HesabCoding> Children
//{
// get { return _children; }
//}
public IList<HesabCoding> HesabCodings { get; set; }
public HesabCoding()
{
HesabCodings = new ObservableCollection<HesabCoding>();
}
[Custom(false, Visibility.Collapsed)]
public int Id
{
get
{
return this.id;
}
set
{
this.id = value;
base.OnPropertyChanged("Id");
}
}
[DisplayName("نام حساب")]
[Custom(false, Visibility.Visible)]
public string Title
{
get
{
return this.title;
}
set
{
this.title = value;
base.OnPropertyChanged("Title");
}
}
[DisplayName("نام کامل حساب")]
[Custom(false, Visibility.Visible)]
public string FullTitle
{
get
{
return this.fullTitle;
}
set
{
this.fullTitle = value;
base.OnPropertyChanged("FullTitle");
}
}
[DisplayName("کد حساب")]
[Custom(false, Visibility.Visible)]
public string HesabCode
{
get
{
return this.hesabCode;
}
set
{
this.hesabCode = value;
base.OnPropertyChanged("HesabCode");
}
}
[DisplayName("کد کامل حساب")]
[Custom(false, Visibility.Visible)]
public string FullHesabCode
{
get
{
return this.fullHesabCode;
}
set
{
this.fullHesabCode = value;
base.OnPropertyChanged("FullHesabCode");
}
}
[Custom(false, Visibility.Collapsed)]
public byte HesabStructure_FK
{
get
{
return this.hesabStructure_FK;
}
set
{
this.hesabStructure_FK = value;
base.OnPropertyChanged("HesabStructure_FK");
}
}
[DisplayName("سطح حساب")]
[Custom(false, Visibility.Visible)]
public string HesabStructure
{
get
{
return this.hesabStructure;
}
set
{
this.hesabStructure = value;
base.OnPropertyChanged("HesabStructure");
}
}
[Custom(false, Visibility.Collapsed)]
public byte HesabEntity_FK
{
get
{
return this.hesabEntity_FK;
}
set
{
this.hesabEntity_FK = value;
base.OnPropertyChanged("HesabEntity_FK");
}
}
[DisplayName("ماهیت حساب")]
[Custom(false, Visibility.Visible)]
public string HesabEntity
{
get
{
return this.hesabEntity;
}
set
{
this.hesabEntity = value;
base.OnPropertyChanged("HesabEntity");
}
}
[Custom(false, Visibility.Collapsed)]
public short HesabGroup_FK
{
get
{
return this.hesabGroup_FK;
}
set
{
this.hesabGroup_FK = value;
base.OnPropertyChanged("HesabGroup_FK");
}
}
[DisplayName("گروه حساب")]
[Custom(false, Visibility.Visible)]
public string HesabGroup
{
get
{
return this.hesabGroup;
}
set
{
this.hesabGroup = value;
base.OnPropertyChanged("HesabGroup");
}
}
[Custom(false, Visibility.Visible)]
public int ParentId
{
get
{
return this.parentId;
}
set
{
this.parentId = value;
base.OnPropertyChanged("ParentId");
}
}
[DisplayName("پایانی")]
[Custom(false, Visibility.Visible)]
public bool IsFinal
{
get
{
return this.isFinal;
}
set
{
this.isFinal = value;
base.OnPropertyChanged("IsFinal");
}
}
[DisplayName("فعال")]
[Custom(false, Visibility.Hidden)]
public bool Active
{
get
{
return this.active;
}
set
{
this.active = value;
base.OnPropertyChanged("Active");
}
}
[Custom(false, Visibility.Collapsed)]
public bool IsAddByUser
{
get
{
return this.isAddByUser;
}
set
{
this.isAddByUser = value;
base.OnPropertyChanged("IsAddByUser");
}
}
[DisplayName("زمان ایجاد")]
[Custom(false, Visibility.Visible)]
public string InsertDateTime
{
get
{
return this.insertDateTime;
}
set
{
this.insertDateTime = value;
base.OnPropertyChanged("InsertDateTime");
}
}
[DisplayName("کاربر ایجاد کننده")]
[Custom(false, Visibility.Visible)]
public string InsertUser
{
get
{
return this.insertUser;
}
set
{
this.insertUser = value;
base.OnPropertyChanged("InsertUser");
}
}
[DisplayName("زمان ویرایش")]
[Custom(false, Visibility.Visible)]
public string UpdateDateTime
{
get
{
return this.updateDateTime;
}
set
{
this.updateDateTime = value;
base.OnPropertyChanged("UpdateDateTime");
}
}
[DisplayName("کاربر ویرایش کننده")]
[Custom(false, Visibility.Visible)]
public string UpdateUser
{
get
{
return this.updateUser;
}
set
{
this.updateUser = value;
base.OnPropertyChanged("UpdateUser");
}
}
HesabCodingDAL:
public ObservableCollection<HesabCoding> HesabCodingSelect(bool onlyActive, out string errorMessage)
{
using (var dbcontext = new AccountingDataContext(AppData.userDbConnectionStri ng))
{
try
{
errorMessage = null;
var Ret = dbcontext.HesabCodingSelect(true);
// var m = new HesabCoding {Ret };
List<HesabCoding> hesabCodingModelList = new List<HesabCoding>();
CastObjectHelper.CastObjectResultToList(Ret, ref hesabCodingModelList);
ObservableCollection<HesabCoding> hesabCodingModelCollection = new ObservableCollection<HesabCoding>(hesabCodingModel List);
return hesabCodingModelCollection;
}
catch (Exception ex)
{
errorMessage = ex.Message;
return null;
}
}
}
کدهای :
HesabCodingListVM
public class HesabCodingListVM : BaseViewModel
{
#region Class Contractor
HesabCodingDAL HesabCodingDAL;
public HesabCodingListVM()
{
HesabCodingDAL = new HesabCodingDAL();
HesabCodingCollection = new ObservableCollection<HesabCoding>();
HesabCodingModelCurrent = new HesabCoding();
HesabCodingSelect();
}
#endregion
#region Public Property
private ObservableCollection<HesabCoding> _HesabCodingCollection;
public ObservableCollection<HesabCoding> HesabCodingCollection
{
get { return this._HesabCodingCollection; }
set
{
this._HesabCodingCollection = value;
PropertyChanged(/*"HesabCodingCollection"*/this, new PropertyChangedEventArgs(nameof(HesabCodingCollect ion)));
}
}
public HesabCoding HesabCodingModelCurrent
{
get;
set;
}
private int selectedIndex;
public int SelectedIndex
{
get { return selectedIndex; }
set
{
selectedIndex = value;
base.OnPropertyChanged("SelectedIndex");
}
}
#endregion
public event PropertyChangedEventHandler PropertyChanged = delegate { };
#region Class Methods
public void HesabCodingSelect()
{
string _errorMessage = "";
int tmpSelectedIndex = SelectedIndex;
ObservableCollection<HesabCoding> _HesabCodingModelCollection = new ObservableCollection<HesabCoding>();
_HesabCodingModelCollection = HesabCodingDAL.HesabCodingSelect(false, out _errorMessage);
if (!string.IsNullOrEmpty(errorMessage))
{
AvinMessageBox.Show("خطا", errorMessage, System.Windows.MessageBoxButton.YesNo, Common.MessageBoxImage.Warning, System.Windows.MessageBoxResult.OK);
}
else
{
HesabCodingCollection = _HesabCodingModelCollection;
}
SelectedIndex = tmpSelectedIndex;
Messenger.Default.Send(this, "HesabCodingListNotify");
}
}
}
<local:HesabCodingListVM x:Key="VM" />
<Grid DataContext="{Binding Source={StaticResource VM}}" Grid.Row="1">
<TreeView ItemsSource="{Binding HesabCodingCollection}">
<TreeView.ItemTemplate>
<HierarchicalDataTemplate ItemsSource="{Binding HesabCodings}">
<TextBlock Text="{Binding Title}" />
</HierarchicalDataTemplate>
</TreeView.ItemTemplate>
</TreeView>
</Grid>
البته در دیزاین این کد از این خط خطا میگیره :
local:HesabCodingListVM x:Key="VM
کد HTML:
Severity Code Description Project File Line Suppression State
Error Value cannot be null.
Parameter name: fileOrServerOrConnection AvinSoft F:\mhd3\Project\MyShoppingProject\AvinApp\AvinSoft\AvinSoft\View\Windows\HesabCodingListView.xaml 13