2015-01-14 1 views
0

나는 바인딩 경로 오류가 발생하는 경우가 있습니다. 그러나 일부 바인딩은 여전히 ​​작동하지만 다른 바인딩은 작동하지 않습니다.Xaml은 경로 오류를 생성하지만 일부는 여전히 작동합니다.

코드 뒤에 :

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> 
나는 다음과 같은 클래스 (복사/붙여 넣기에만 해당 비트)가

오류는 :

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')

아직 템플릿을 인수 분해의 부분 확보하지 않은,하지만 난이 여기에 문제가 있다고 생각하지 않습니다.

오류가 발생하더라도 프로그램은 내가 원하는 것을 보여줍니다. 그러나 다음에 추가 한 바인딩은 동일한 오류 유형 (잘못된 경로)을 제공하는 출력에서 ​​전혀 작동하지 않습니다. 여기서 내가 뭘 잘못하고 있니?

+1

DataContext는 XAML과 백 엔드 코드의 생성자에서 설정합니다. 나는 이것이 당신의 실수가있는 곳이라고 생각합니다. XAML의 DataContext 행을 제거하십시오. –

+0

그것은 매력처럼 작동했습니다. (왜 아직도 효과가 있는지 궁금합니다.) 귀하의 답변을 확인하고 싶습니다. 답장으로 쓸 수는 없습니까? – madks13

+0

문제 없습니다. 바인딩은 때로는 디버그하는 데 어려움이 될 수 있습니다. :-) –

답변

0

DataContext는 XAML 및 생성자에서 설정합니다.

이 출력에 오류를 일으키는 같이 XAML에서의 DataContext 라인을 제거 바인딩 장애가 발생한

DataContext="{Binding Source={RelativeSource Self}}" 

, 오류를 발생하고 응용 프로그램을 중단하지 않을 적용되지만 출력에 표시됩니다.

나는 응용 프로그램을 실행하기 전에 바인딩 오류를 보는 좋은 방법은 인텔리 센스가 작동하는지 확인하는 것입니다. 그렇다면, 당신은 잘 가야합니다.

+0

그건 그렇고, intellisense가 작동하는지 어떻게 확인합니까? – madks13

+0

XAML에서 바인딩을 입력하는 동안 개체의 속성이 Intellisense 목록에 있어야합니다. –

+0

흠, 이상한데, 지금도 목록에서 내 물건의 속성을 찾을 수 없기 때문입니다. WPF 객체의 "바인딩", "경로", "모드"및 기타 모든 것에 대해 언급하지 않는 한. – madks13

관련 문제