wpf2017. 7. 25. 17:41

List는 List<ConvertOrderKey>이런식으로 자료가 들어가 있고


ItemTemplate안에는 

<Button Content="주문확인" Width="70" Command="{Binding ElementName=xListView, Path = DataContext.OrderClickCommand}" CommandParameter="{Binding}" />


이런식으로 구현하였다.

커맨드 파라미터는 그냥 ConvertOrderKey모델 전체를 넘겼다.


viewModel에서는


1
2
3
4
5
6
7
8
9
10
11
12
13
14
 private RelayCommand<ConvertOrderKey> _orderClickCommand;
 
        public RelayCommand<ConvertOrderKey> OrderClickCommand
        {
            get
            {
                return _orderClickCommand
                  ?? (_orderClickCommand = new RelayCommand<ConvertOrderKey>(
                    param =>
                    {
                        var temp = param;
                    }));
            }
        }

이렇게 구현하였다.

param에 모델데이터가 전부 넘어온다.


Posted by 동동(이재동)
wpf2017. 7. 17. 16:54

일단 Command를 만든다.

1
2
        private bool _deleteCommand = true;
        public RelayCommand DeleteCommand { get; private set; }
 


ViewModel 생성자에 넣기

1
2
3
4
5
 public MainViewModel()
        {
            DeleteCommand = new RelayCommand(ExcuteDeleteCommand, () => _deleteCommand);
            OrderMenuList = new ObservableCollection<OrderMenu>();
        }



1
2
3
4
 private void ExcuteDeleteCommand()
        {
            OrderMenuList.RemoveAt(OrderMenuList.Count - 1);
        }


xaml코드에는


1
<Button x:Name="xdelete" Content="삭제"  Height="50" Margin="20" Command="{Binding DeleteCommand}" />


여러가지 파라미터를 사용하고 싶으면 여기 참고

https://msdn.microsoft.com/en-us/magazine/dn237302.aspx

Posted by 동동(이재동)
Windows Phone 72011. 3. 31. 15:13
xaml 상단에 이렇게 datacontext를 연결하고
 
DataContext="{Binding BookViewModel, Source={StaticResource Locator}}"
 
<phone:PhoneApplicationPage
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
    xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:controls="clr-namespace:HugeFlow.FortuneCoins.Controls"
    xmlns:uc="clr-namespace:HugeFlow.FortuneCoins.Controls"
    xmlns:wp="clr-namespace:HugeFlow.Phone.Controls;assembly=HugeFlow.Phone.Controls"
    xmlns:Custom="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity" xmlns:HugeFlow_CommandPattern_Interactivity="clr-namespace:HugeFlow.CommandPattern.Interactivity;assembly=HugeFlow.MVVM" 
    x:Class="HugeFlow.FortuneCoins.Views.BookView"
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    SupportedOrientations="Portrait" Orientation="Portrait"
    mc:Ignorable="d" d:DesignHeight="768" d:DesignWidth="480"    
    shell:SystemTray.IsVisible="False" DataContext="{Binding BookViewModel, Source={StaticResource Locator}}">
 
behind에서 datacontext를 연결한후
 
private LocationPermissionViewModel _viewModel;
 
     public LocationPermissionView()
     {
         InitializeComponent();
         _viewModel = this.DataContext as LocationPermissionViewModel;
     }
 
그리고 커맨드를 사용할 버튼 이벤트에 이렇게

private void NoButton_Click(object sender, RoutedEventArgs e)
      {
          _viewModel.NoButtonClickCommand.Execute(null);
      }
Posted by 동동(이재동)