Let's take a look at how to turn a page into a startup page
In the onLanched event, put,
Window.Current.Content = _rootFrame;
Window.Current.Activate();
var _rootFrame = new Frame();
_rootFrame.Navigate(typeof(ItemsPage), sampleData.ItemGroups);
/// Window.Current.Content , .Activate();
Then look at what's in the ItemsPage, look at the inheritance relationship
public sealed partial class ItemsPage : Application6.Common.LayoutAwarePage
[Windows.Foundation.Metadata.WebHostHidden] public class LayoutAwarePage : Page///or inherit from page, then see why they have LayoutAwarePage, this class
New LayoutAwarePage() will be called before new ItemsPage(), that is, the constructor and fields in LayoutAwarePage will be run first; because of the inheritance relationship
The DataContext that LayoutAwarePage inherits from page is public, this.DataContext = _defaultViewModel;, which adds data context to the page inherited from LayoutAwarePage
In ItemPage, call this protected override void OnNavigatedTo(NavigationEventArgs e) { this.DefaultViewModel["Items"] = e.Parameter; } to set datacontext for itemPage, because the datacontext of itempage inherits from LayoutAwarePage and is pointing to _defaultViewModel, reference, when the object that _defaultViewModel only wants to change, the datacontext for itempage will also change, so why does LayoutAwarePage have protected IObservableMap DefaultViewModel { get { return _defaultViewModel; } }? , look at its gaze
//////Gets an implementation of set as the///page's default . This instance can be bound and surfaces///property change notifications making it suitable for use as a trivial view model.///By default, datacontext is set for each inherited from LayoutAwarePage, this is just for trial ViewMoDEL, if you want to change it this.DefaultViewModel["Items"] = e.Parameter;, set different strings and objects, that's it 8 ItemsPage has a CollectionViewSource, object, CollectionViewSource. SOURCE , referenced to e.Parameter by binding to this.DefaultViewModel["Items"] Then the control in the ItemsPage can be bound to the CollectionViewSource
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다: