wpf2021. 11. 18. 18:01

private bool IsDiffList<T>(List<T> list1, List<T> list2)
        {
            var diff1 = list1.Except(list2);
            var diff2 = list2.Except(list1);

            var resultDiff = diff1.Concat(diff2).ToList();

            if (resultDiff.Count > 0)
                return true;
            else
                return false;
        }

 

if (IsDiffList<OrderInfo>((xProfitOrderListbox.ItemsSource as List<OrderInfo>).ToList(), _service.OrderInfoList))
                {
                    xProfitOrderListbox.ItemsSource = _service.OrderInfoList;
                    xProfitOrderListbox.Items.Refresh();
                }

 

이런식으로 반복적으로 item을 넣어야 하는곳에 넣어준다. timer를 이용하면 객체를 계속 생성하기때문에

 

무조건 넣어주면 메모리 Leak 이 걸린다. 그렇기 떄문에 변경될때만 적용되게 해야한다.

'wpf' 카테고리의 다른 글

public (string name, int age) GetUser()  (0) 2022.10.26
PeriodicTimer  (0) 2022.08.31
싱글톤 쓰기  (0) 2021.08.24
Combox 에 Enum 바인딩  (0) 2021.05.06
WPF에서 기본적으로 제공해주는 BoolToVisConverter 컨버터  (0) 2020.04.28
Posted by 동동(이재동)
wpf2019. 3. 21. 17:44

List를 그대로 대입시켜버리면 해당 객체가 바뀌기때문에


clone, deep copy를 해야한다.


List<Book> books_2 = books_1.ConvertAll(book => new Book());



내가 봤을때는 이게 가장 나은 방법같다.

https://stackoverflow.com/questions/14007405/how-create-a-new-deep-copy-clone-of-a-listt

Posted by 동동(이재동)
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 동동(이재동)
Windows Phone 82013. 3. 4. 13:41

 

List 에 1,2,3 이 있으면 3,2,1 로 불러오고 싶을떄

 

List의 Reserve() 메소드를 이용한다.

 

하지만 옵저버블 컬렉션에서는 안되지만 방법이 있을듯하다.

 

 

 

참고 : http://msdn.microsoft.com/ko-kr/library/b0axc2h2(v=vs.85).aspx

Posted by 동동(이재동)
Windows Phone 72012. 3. 8. 16:27

현재 Mnet을 작업하는데 Mnet에서 PlayList를 순서를 마음대로 바꿀수 있게 바꿔야 했다.

아이폰에서나 가능한 순서 바꾸기… 아무리 찾아봐도 순정 Listbox에는 할수 없다.

아이폰이나 안드로이드는 기본컨트롤에서 바꿀수 있는데 왜 윈폰은 없냐고!!!

하지만 누군가 만들어 놓은게 있어서 고맙게 이용해서 성공했다.

 

 

수정모드를 설정할수 있으며

수정모드에서 삭제버튼등을 추가할려면 아쉽게도 DataTemplate을 바꾼후 다시 리로딩해서 수정모드로 가야 한다.

바꾸는 방법은 포스팅했으니 참고 바란다.

자세한 사항은 소스를 참고하자

내가 참고한곳 : http://blogs.msdn.com/b/jasongin/archive/2011/01/03/wp7-reorderlistbox-improvements-rearrange-animations-and-more.aspx

내가 새로 만든 테스트 소스

Posted by 동동(이재동)
Windows Phone 72012. 1. 30. 20:39

코레일을 하다가 index값을 구해야 하는 경우가 생겼다.

하지만 Linq에서 where 문을 이용해서 firstOrDefault()를 이용해서 값을 얻어 왔지만 그 값이 List의 몇번째 값인지는

알수 없었다. 다른데서는 지원되는데 윈폰7의 compact .net framework에서는 제공되지 않는것인가? ㅠㅠ

그래서 여러가지 방법중 좋은 방법을 찾았다.

그 방법은 바로..두구두구두구..

그냥 직접 제작하는것이다 하하하

일단 구현한 클래스는 이렇다.

using System;
using System.Collections.Generic;

namespace GloryApp.Utils
{
    public static class IEnumerableExtensions
    {
        public static int IndexWhere<TSource>(this IEnumerable<TSource> source, Func<TSource, bool> predicate)
        {
            var enumerator = source.GetEnumerator();

            int index = 0;

            while (enumerator.MoveNext())
            {
                TSource obj = enumerator.Current;

                if (predicate(obj))

                    return index;

                index++;
            }

            return -1;
        }

        public static int IndexWhere<TSource>(this IEnumerable<TSource> source, Func<TSource, int, bool> predicate)
        {
            var enumerator = source.GetEnumerator();

            int index = 0;

            while (enumerator.MoveNext())
            {
                TSource obj = enumerator.Current;

                if (predicate(obj, index))

                    return index;

                index++;
            }

            return -1;
        }
    }
}

 

그리고 위의 프레임워크를 사용할 클래스에 using 하면

var temp = siList.IndexWhere(c => c.h_srcar_no == currenSrcarNo);

이런식으로 얻어 올수 있다.

 

참고 : http://snipplr.com/view/53625/

Posted by 동동(이재동)