I have a dropbox:
<ComboBox Height="23" Name="DriveSelection" Width="120"
ItemsSource="{Binding Path=FixedDrives}"
DisplayMemberPath="Name"
SelectedItem="{Binding Path=DriveSelection_SelectionChanged}"
IsSynchronizedWithCurrentItem="True"
IsEnabled="{Binding DriveIsEnabled}"
SelectedValue="{Binding DriveSelected}"
/>
with this bindings:
private ObservableCollection<DriveInfo> fixedDrives;
public ObservableCollection<DriveInfo> FixedDrives
{
get
{
if (this.fixedDrives != null)
return this.fixedDrives;
this.fixedDrives = new ObservableCollection<DriveInfo>(Enumerable.Where<DriveInfo>((IEnumerable<DriveInfo>)DriveInfo.GetDrives(), (Func<DriveInfo, bool>)(driveInfo => driveInfo.DriveType == DriveType.Fixed)));
return this.fixedDrives;
}
}
public DriveInfo DriveSelection_SelectionChanged
{
get
{
return this.driveSelection;
}
set
{
if (value == this.driveSelection)
return;
this.driveSelection = value;
UpdatePathManager();
this.OnPropertyChanged("DriveSelection_SelectionChanged");
}
}
public object DriveSelected
{
get
{
return _driveSelected;
}
set
{
_driveSelected = value;
RaisePropertyChanged("DriveSelected");
}
}
and While doing page initialization:
public PathSelectionPageViewModel(PathSelectionPage _page)
{
this.page = _page;
this.root = Path.GetPathRoot(App.Instance.PathManager.InstallRoot).ToUpperInvariant();
this.DriveSelected = (object)this.root;
//this.page.DriveSelection.SelectedValue = (object)this.root;
this.DriveIsEnabled = true
//this.page.DriveSelection.IsEnabled = true
this.driveSelection = new DriveInfo(this.root);
}
on the last line:
this.driveSelection = new DriveInfo(this.root);
I'm geting null reference exception in this line:
private void UpdatePathManager()
{
string newRoot = this.driveSelection.ToString(); <--- this line
//string newRoot = this.page.DriveSelection.SelectedValue.ToString();
}
As you can see I was just trying to change reading data straight from View into bindings but I have problems with this. What shoudl be changed in order to fix it?
@Update As I just found: problem is in during processing bindings. Wpf is processing bindings in this order ->
- FixedDrives
- Selection Changed
- DriveIsEnabled
- DriveSelected
and processing DriveSelected
is firing the `DriveSelection_SelectionChanged" with value = null. and this Is causing the problems.