Reputation: 155
I have a case where I get a binding path error. However, some of the bindings still work while others don't. I have the following classes (copy/pasted only the relevant bits) :
Code behind :
class RSSManager : BaseViewModel
{
#region Resources
private Platforms _platformsList;
public Platforms PlatformsList
{
get { return _platformsList; }
set
{
_platformsList = value;
NotifyPropertyChanged("PlatformsList");
}
}
private List<IActivity> _mainActivitiesList = new List<IActivity>();
public List<IActivity> MainActivitiesList
{
get { return _mainActivitiesList; }
set
{
_mainActivitiesList = value;
NotifyPropertyChanged("MainActivitiesList");
}
}
private ObservableCollection<IActivity> _activitiesList = new ObservableCollection<IActivity>();
public ObservableCollection<IActivity> ActivitiesList
{
get { return _activitiesList; }
set
{
_activitiesList = value;
NotifyPropertyChanged("ActivitiesList");
}
}
private ObservableCollection<IActivity> _alertsList = new ObservableCollection<IActivity>();
public ObservableCollection<IActivity> AlertsList
{
get { return _alertsList; }
set
{
_alertsList = value;
NotifyPropertyChanged("AlertsList");
}
}
private ObservableCollection<IActivity> _invasionsList = new ObservableCollection<IActivity>();
public ObservableCollection<IActivity> InvasionsList
{
get { return _invasionsList; }
set
{
_invasionsList = value;
NotifyPropertyChanged("InvasionsList");
}
}
private ObservableCollection<IActivity> _outbreaksList = new ObservableCollection<IActivity>();
public ObservableCollection<IActivity> OutbreaksList
{
get { return _outbreaksList; }
set
{
_outbreaksList = value;
NotifyPropertyChanged("OutbreaksList");
}
}
private ObservableCollection<IActivity> _doneList = new ObservableCollection<IActivity>();
public ObservableCollection<IActivity> DoneList
{
get { return _doneList; }
set
{
_doneList = value;
NotifyPropertyChanged("DoneList");
}
}
#endregion
}
public partial class Activities : Page, IOptions
{
Options.OptionsActivities _options = new Options.OptionsActivities();
RSSManager _manager = new RSSManager();
public Activities()
{
InitVars();
InitializeComponent();
DataContext = _manager;
UpdateCheckBoxes();
UpdateTabsHeaders();
}
}
Activities.xaml :
<Page x:Class="Warframe_Activity_Manager.Views.Activities"
DataContext="{Binding Source={RelativeSource Self}}"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="718" d:DesignWidth="1024"
GotFocus="Page_GotFocus"
Title="Activities">
<Grid Name="MainGrid" Background="Transparent">
<Grid.RowDefinitions>
<RowDefinition Height="30" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<StackPanel Name="PlatformChoices" Orientation="Horizontal" Background="Transparent">
<Label Name="ChoicePCLabel" Content="Show PC Activities" Foreground="Aqua" VerticalAlignment="Center"></Label>
<CheckBox Name="ChoicePC" VerticalAlignment="Center" Click="Platform_Click"/>
<Label Name="ChoicePS4Label" Content="Show PlayStation 4 Activities" Foreground="Aqua" VerticalAlignment="Center"></Label>
<CheckBox Name="ChoicePS4" VerticalAlignment="Center" Click="Platform_Click"/>
<Label Name="ChoiceXB1Label" Content="Show XBox One Activities" Foreground="Aqua" VerticalAlignment="Center"></Label>
<CheckBox Name="ChoiceXB1" VerticalAlignment="Center" Click="Platform_Click"/>
</StackPanel>
<Button Name="Refresh" HorizontalAlignment="Right" Content="Refresh" Click="Refresh_Click"/>
<TabControl Name="Tabs" Grid.Row="1" Background="Transparent">
<TabItem Name="TabAll" Header="All Activities" BorderThickness="0">
<ListView Name="ListAll" Background="Transparent" ItemsSource="{Binding ActivitiesList}" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" HorizontalContentAlignment="Stretch">
<ListView.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="1*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="1*"/>
<RowDefinition Height="1*"/>
</Grid.RowDefinitions>
<StackPanel Name="ActivityTypeContainer" Orientation="Horizontal" HorizontalAlignment="Left">
<Label Name="ActivityTypeLabel" VerticalAlignment="Center" Foreground="Red" Content="Activity Type :"/>
<Label Name="ActivityType" VerticalAlignment="Center" Foreground="Red" Content="{Binding Path=Type}"/>
</StackPanel>
<StackPanel Name="ActivityPlatformContainer" Grid.Column="1" Orientation="Horizontal" HorizontalAlignment="Right" Margin="0, 0, 10, 0">
<Label Name="ActivityPlatformLabel" VerticalAlignment="Center" Foreground="Blue" Content="Platform :"/>
<Label Name="ActivityPlatform" VerticalAlignment="Center" Foreground="Blue" Content="{Binding Path=Platform}"/>
</StackPanel>
<StackPanel Name="ActivityInfoContainer" Grid.Row="1" Orientation="Horizontal" HorizontalAlignment="Left">
<Label Name="ActivityInfoLabel" VerticalAlignment="Center" Foreground="Orange" Content="Activity Information : "/>
<Label Name="ActivityInfo" VerticalAlignment="Center" Foreground="Orange" Content="{Binding Path=Info}"/>
</StackPanel>
<StackPanel Name="ActivityDoneContainer" Grid.Column="1" Grid.Row="1" Orientation="Horizontal" HorizontalAlignment="Right" Margin="0, 0, 10, 0">
<Label Name="ActivityDoneLabel" VerticalAlignment="Center" Foreground="Green" Content="Finished : "/>
<CheckBox Name="ActivityDone" VerticalAlignment="Center" IsChecked="{Binding Path=Done, Mode=TwoWay}" Click="ActvityDone_Click"/>
</StackPanel>
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</TabItem>
</TabControl>
</Grid>
The errors :
System.Windows.Data Error: 40 : BindingExpression path error: 'ActivitiesList' property not found on 'object' ''RelativeSource' (HashCode=16143157)'. BindingExpression:Path=ActivitiesList; DataItem='RelativeSource' (HashCode=16143157); target element is 'ListView' (Name='ListAll'); target property is 'ItemsSource' (type 'IEnumerable') System.Windows.Data Error: 40 : BindingExpression path error: 'AlertsList' property not found on 'object' ''RelativeSource' (HashCode=16143157)'. BindingExpression:Path=AlertsList; DataItem='RelativeSource' (HashCode=16143157); target element is 'ListView' (Name='ListAlerts'); target property is 'ItemsSource' (type 'IEnumerable') System.Windows.Data Error: 40 : BindingExpression path error: 'InvasionsList' property not found on 'object' ''RelativeSource' (HashCode=16143157)'. BindingExpression:Path=InvasionsList; DataItem='RelativeSource' (HashCode=16143157); target element is 'ListView' (Name='ListInvasions'); target property is 'ItemsSource' (type 'IEnumerable') System.Windows.Data Error: 40 : BindingExpression path error: 'OutbreaksList' property not found on 'object' ''RelativeSource' (HashCode=16143157)'. BindingExpression:Path=OutbreaksList; DataItem='RelativeSource' (HashCode=16143157); target element is 'ListView' (Name='ListOutbreaks'); target property is 'ItemsSource' (type 'IEnumerable') System.Windows.Data Error: 40 : BindingExpression path error: 'DoneList' property not found on 'object' ''RelativeSource' (HashCode=16143157)'. BindingExpression:Path=DoneList; DataItem='RelativeSource' (HashCode=16143157); target element is 'ListView' (Name='ListDone'); target property is 'ItemsSource' (type 'IEnumerable')
I haven't yet gotten to the part of factoring templates, but I don't think that is the issue here.
As stated, even though I get the errors, the program is showing what I want. However, the bindings I added next are not working at all with the output giving the same error types (wrong path). What am I doing wrong here?
Upvotes: 0
Views: 687
Reputation: 9713
You are setting the DataContext in the XAML and also in the Constructor.
Remove the DataContext line in the XAML as this is causing the errors in the output:
DataContext="{Binding Source={RelativeSource Self}}"
In the event of binding failures, the application won't raise any errors and stop the application, but they will display them in the Output.
I find that a good way of seeing any binding errors before running the app would be to check if the intellisense is working. If it is, then you should be good to go.
Upvotes: 0