English 中文(简体)
观测 未更新的收款情况
原标题:ObservableCollection not updating

我感到,这真的接近于让它发挥作用。 我有一台电梯,我希望用户能够每月从一个 com箱中抽取,并显示该日期的电梯。 现在,无论我选择什么从 com子上,都没有任何东西。 我可以通过使用名单箱和纽托邦活动来开展工作,但不能真正地更新其清点和显示新月选择的情况。 它不是这样做的正确途径。 我给我带来了很多时间,如果有人能够看一看,也许会给我一些点人,我真的赞赏。

--------Model Class---------

         public partial class SchedulePage : Page, INotifyPropertyChanged 
{
    public int pick2;
     public event PropertyChangedEventHandler PropertyChanged;
    MainWindow _parentForm;
    public int pick;
    Schedule sched = new Schedule();

    static GregorianCalendar _gc = new GregorianCalendar();


   public SchedulePage(MainWindow parentForm)
    {
        InitializeComponent();





    //    this.PropertyChanged += comboMonth_SelectionChanged;


        pick = Convert.ToInt32(comboMonth.SelectedItem);
        _parentForm = parentForm;



    }

    public void NotifyPropertyChanged(String info)
    {
        if (PropertyChanged != null)
        {
            PropertyChanged(this, new PropertyChangedEventArgs(info));
        }
    }

    private int _nameofmonth ;

    public int NameofMonth
    {
        get
        {
            return this._nameofmonth;
        }

        set
        {
            if (value != this._nameofmonth)
            {
                this._nameofmonth = value;
                NotifyPropertyChanged("NameofMonth");
            }
        }
    }


 // void TheViewModel_PropertyChanged(object src, PropertyChangedEventArgs e)
    private void comboMonth_SelectionChanged(object sender, SelectionChangedEventArgs e)
  {
    //{

      //  if (e.PropertyName == "NameofMonth")
       // {
            //var date = new DateTime(2011, 11, 1);
            //makeCalender(date);

        _parentForm.bindings.schedule.Clear();
            var t = new List<Schedule>();
            DateTime curr = DateTime.Now;
            int jeez = comboMonth.SelectedIndex+1;
            //  comboMonth.Items.Add(curr.Month);
            DateTime newcurr = new DateTime(2011, NameofMonth+1, 1);
            //   pickdate = datePickercal.SelectedDate;
            //  DateTime newcurr = new DateTime(curr.Year, curr.Month, 1);
            var cal = System.Globalization.DateTimeFormatInfo.CurrentInfo.Calendar;
            var ms = cal.GetWeekOfYear(new DateTime(newcurr.Year, newcurr.Month, 1), System.Globalization.CalendarWeekRule.FirstDay, System.DayOfWeek.Sunday);
            for (var i = 1; newcurr.Month == NameofMonth+1; newcurr = newcurr.AddDays(1))
            {

                var month_week = (newcurr.Day / 7);
                sched.MonthWeek = newcurr.GetWeekOfMonth().ToString();
                sched.Month = newcurr.Month.ToString();
                sched.Year = newcurr.Year.ToString();
                sched.day = newcurr.Day.ToString();
                sched.WeekOfYear = cal.GetWeekOfYear(newcurr, System.Globalization.CalendarWeekRule.FirstDay, DayOfWeek.Sunday).ToString();
                sched.dayofweek = newcurr.DayOfWeek.ToString();
                t.Add(sched);

                _parentForm.bindings.schedule.Add(new Schedule { WeekNo = newcurr.GetWeekOfMonth() - 1, WeekDay = (int)newcurr.DayOfWeek, day = newcurr.Day.ToString() });

            }
            lblDate.Content = (newcurr.Month - 1) + "/" + newcurr.Year;
            //testGrid.ItemsSource = t;
            comboMonth.DataContext = _parentForm.bindings;
            DataContext = _parentForm.bindings;

       // }

    }

页: 1

   <ComboBox  SelectedIndex="{Binding NameofMonth}" Grid.ColumnSpan="2" Height="23" HorizontalAlignment="Left" Margin="6,0,0,0" Name="comboMonth" VerticalAlignment="Top" Width="120" SelectionChanged="comboMonth_SelectionChanged">
            <ComboBoxItem Content="1" IsSelected="False" />
            <ComboBoxItem Content="2" />
            <ComboBoxItem Content="3" />
            <ComboBoxItem Content="4" />
            <ComboBoxItem Content="5" />
            <ComboBoxItem Content="6" />
            <ComboBoxItem Content="7" />
            <ComboBoxItem Content="8" />
            <ComboBoxItem Content="9" />
            <ComboBoxItem Content="10" />
            <ComboBoxItem Content="11" IsSelected="False" />
            <ComboBoxItem Content="12" />
        </ComboBox>
最佳回答

你们需要使你在可观察的Collection中所使用的诗歌能够用于识别。

例:

<viewModels:LocationsViewModel x:Key="viewModel" />
.
.
.    
<ListView
    DataContext="{StaticResource viewModel}"
    ItemsSource="{Binding Locations}"
    IsItemClickEnabled="True"
    ItemClick="GroupSection_ItemClick"
    ContinuumNavigationTransitionInfo.ExitElementContainer="True">

    <ListView.ItemTemplate>
        <DataTemplate>
            <StackPanel Orientation="Horizontal">
                <TextBlock Text="{Binding Name}" Margin="0,0,10,0" Style="{ThemeResource ListViewItemTextBlockStyle}" />
                <TextBlock Text="{Binding Latitude, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Style="{ThemeResource ListViewItemTextBlockStyle}" Margin="0,0,5,0"/>
                <TextBlock Text="{Binding Longitude, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Style="{ThemeResource ListViewItemTextBlockStyle}" Margin="5,0,0,0" />
            </StackPanel>
        </DataTemplate>
    </ListView.ItemTemplate>
</ListView>

public class LocationViewModel : BaseViewModel
{
    ObservableCollection<Location> _locations = new ObservableCollection<Location>();
    public ObservableCollection<Location> Locations
    {
        get
        {
            return _locations;
        }
        set
        {
            if (_locations != value)
            {
                _locations = value;
                OnNotifyPropertyChanged();
            }
        }
    }
}

public class Location : BaseViewModel
{
    int _locationId = 0;
    public int LocationId
    {
        get
        {
            return _locationId;
        }
        set
        {
            if (_locationId != value)
            {
                _locationId = value;
                OnNotifyPropertyChanged();
            }
        }
    }

    string _name = null;
    public string Name
    {
        get
        {
            return _name;
        }
        set
        {
            if (_name != value)
            {
                _name = value;
                OnNotifyPropertyChanged();
            }
        }
    }

    float _latitude = 0;
    public float Latitude 
    { 
        get
        {
            return _latitude;
        }
        set
        {
            if (_latitude != value)
            {
                _latitude = value;
                OnNotifyPropertyChanged();
            }
        }
    }

    float _longitude = 0;
    public float Longitude
    {
        get
        {
            return _longitude;
        }
        set
        {
            if (_longitude != value)
            {
                _longitude = value;
                OnNotifyPropertyChanged();
            }
        }
    }
}

public class BaseViewModel : INotifyPropertyChanged
{
    #region Events
    public event PropertyChangedEventHandler PropertyChanged;
    #endregion

    protected void OnNotifyPropertyChanged([CallerMemberName] string memberName = "")
    {
        if (PropertyChanged != null)
        {
            PropertyChanged(this, new PropertyChangedEventArgs(memberName));
        }
    }
}
问题回答

暂无回答




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签