'변경'에 해당되는 글 1건

  1. 2012.12.06 [wp8] ViewModel에서 Applicaionbar를 변경해보자.
Windows Phone 82012. 12. 6. 16:25

일단 내가 하고자 하는것은 멜론 플레이 리스트에 수정모드와 일반모드가 있다.

 

일반모드에서 ApplicationBar에 편집 버튼을 누르면 ApplicationBar에 편집을 위한 다른 버튼이 생기게 하는게 목표다(삭제라든지)

 

일단 behind에서 하면 아주 쉽지만 ViewModel에서 하는방법은 없을까?.. 모르겠다..

 

그래성 생각한 방법이 IsReorderEnabled 란 프로퍼티를 만들고

 

 

 

private bool _isReorderEnabled;
 
       public bool IsReorderEnabled
       {
           get
           {
               return _isReorderEnabled;
           }
           set
           {
               Set<bool>(ref _isReorderEnabled, value); 
           }
       }       

 

그냥 View Behind코드에서 변경되었을때 이벤트를 걸었다.

 

public partial class PlaylistDetailView : PhoneApplicationPage
    {
        public PlaylistDetailView()
        {
            InitializeComponent();
            this.Loaded += PlaylistDetailView_Loaded;
        }
 
        private void PlaylistDetailView_Loaded(object sender, RoutedEventArgs e)
        {         
            (DataContext as PlaylistDetailViewModel).PropertyChanged += PlaylistDetailView_PropertyChanged;
        }
 
        void PlaylistDetailView_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            if (e.PropertyName == "IsReorderEnabled")
            {
                if ((DataContext as PlaylistDetailViewModel).IsReorderEnabled == true)
                {
                    ApplicationBar = Application.Current.Resources["PlayListDetailEditAppBar"] as ApplicationBar;
                }
                else
                {
                    ApplicationBar = Application.Current.Resources["PlayListDetailAppBar"] as ApplicationBar;
                }
            }
        }
    }

 

머 이런방법도 있다 ㅋㅋ

Posted by 동동(이재동)