블로그 이미지
Kanais
Researcher & Developer 퍼즐을 완성하려면 퍼즐 조각들을 하나 둘씩 맞춰나가야 한다. 인생의 퍼즐 조각들을 하나 둘씩 맞춰나가다 보면 인생이란 퍼즐도 완성되는 날이 오려나...?

calendar

1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30

Notice

04-28 07:57

Recent Post

Recent Comment

Recent Trackback

Archive

2021. 12. 8. 08:59 MyLife/Cycle

러버덕 악세사리. 삑삑 소리나고 불도 나와요~

 

posted by Kanais
2021. 11. 24. 15:34 Programming/WPF

작성 날짜 : 2021.11.24

개발 환경 : Visual Studio 2019 Community

운영 체제 : Windows 10

 

처음에는 Grid에 동적으로 할당하려고 ItemControl과 여러 뻘짓을 하다가... UniformGrid라는 좋은 panel을 발견!

제가 원하는 딱!! 그 panel입니다.

 

UniformGrid는 Grid 처럼 자식 Control들이 배치되나.. Grid 처럼 Row, Column을 일일이 Definition 해줄 필요가 없이, Rows, Columns 을 설정해주면 그에 따라 자동으로 같은 크기로 배치해주는 Panel입니다. 아래 이미지와 같이 말이죠.

아래 이미지는 뭘 그리려는 거냐아.. 반도체 Wafer에 Die들의 Map을 그려주는 겁니다... 

Die들을 검사하고 검사결과에 따라 Display해주는 Button들의 Background 색상을 변경해줘야하고,, 

처음 시작할때 DieMap에 따라 Die가 없는 부분은 또, Visibility를 hidden 처리도 해줘야하죠.

일단은.. Xaml에서 UniformGrid 코드입니다.

이.. 코드가 정확히 맞다고는 할 수가 없습니다. 저도 공부하면서 WPF MVVM 개발을 진행중이다보니..

여튼, UniformGrid의 Rows, Columns 는 <ItemsControl.ItemsPanel> 설정해줘야 적용이 가능하고요, DataBinding 또한 같이 해줍니다. UpdateSourceTrigger=PropertyChanged 속성의 경우에는... 컴파일러에서는 Warning을 띄우는데,, 잘모르겠네요.

<UniformGrid Height="550" Width="900" >
    <ItemsControl ItemsSource="{Binding DiemapButtonCollection}">
    	<ItemsControl.ItemsPanel>
			<ItemsPanelTemplate>
				<UniformGrid Rows="{Binding Number_Row, UpdateSourceTrigger=PropertyChanged}" 
							Columns="{Binding Number_Column, UpdateSourceTrigger=PropertyChanged}"/>
            </ItemsPanelTemplate>
		</ItemsControl.ItemsPanel>
		<ItemsControl.ItemTemplate>
		<DataTemplate>
			<Button Content="{Binding Content, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" 
					Command="{Binding Command}"
					CommandParameter="{Binding CommandParameter}"
					FontSize="{Binding FontSize}"
					Background="{Binding Background, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
					IsEnabled="{Binding isEnabled, Converter={etc:BoolToVisibilityConverter}}"
					Visibility="{Binding Visibility, Converter={etc:BoolToVisibilityConverter}}"
					/>
			</DataTemplate>
		</ItemsControl.ItemTemplate>
	</ItemsControl>
</UniformGrid>

 

그리고, CS코드는..

DataBinding 한 코드. (ViewModel 부분)

private ObservableCollection<DieMapItem> _diemap_button_collection = new ObservableCollection<DieMapItem>();
public ObservableCollection<DieMapItem> DiemapButtonCollection
{
	get => _diemap_button_collection;
	set
	{
		Set(ref _diemap_button_collection, value, false, "DiemapButtonCollection");
		INotifyPropertyChanged();
	}
}

private void INotifyPropertyChanged()
{
	throw new NotImplementedException();
}

ObservableCollection에서 사용한 DieMapItem Class

ObservableCollection에 있는 Item들 중에서 속성변경 후 적용하려면,, Type의 내부 코드에 NotifyPropertyChaged를 설정해줘야 UI에 반영이 됩니다.

public class DieMapItem : INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;

        public int ID_Item { get; set; }
        public string Content { get; set; }
        public ICommand Command { get; set; }
        public string CommandParameter { get; set; }
        public int FontSize { get; set; }

        private Brush _background;
        public Brush Background
        {
            get => _background;
            set
            {
                _background = value;
                NotifyPropertyChanged("Background");
            }
        }

        private bool _visibility;
        public bool Visibility
        {
            get => _visibility;
            set
            {
                _visibility = value;
                NotifyPropertyChanged("Visibility");
            }
        }

        private bool _isEnabled;
        public bool IsEnabled
        {
            get => _isEnabled;
            set
            {
                _isEnabled = value;
                NotifyPropertyChanged("IsEnabled");
            }
        }

        private void NotifyPropertyChanged(string v)
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(v));
        }
    }

그리고 ObservableCollection에 Button들 추가하는 부분은 아래와 같이 추가해서 넣어주면 됩니다.

DiemapButtonCollection.Add(CreateButton(nDieIndex, isColor, isEnebled));

private DieMapItem CreateButton(int _dieIndex, bool _change_color, bool _isEnabled)
        {
            DieMapItem button = new DieMapItem
            {
                ID_Item = _dieIndex,
                Command = DiemapButtonCommand,
                CommandParameter = _dieIndex.ToString(),
                Content = _dieIndex.ToString(),
                FontSize = 8,
                Visibility = _isEnabled,
                IsEnabled = _isEnabled
            };

            if (_isEnabled)
            {
                button.Background = _change_color ? new SolidColorBrush(Colors.Yellow) : new SolidColorBrush(Colors.Black);
            }

            return button;
        }

그리고 ObservableCollection의 Item 들 중에서 특정 Item에 속성을 변경하고 싶다~ 하면, 아래와 같이 ObservableCollection[index].property로 접근해서 변경해주면 됩니다.

private void ChangeButtonBackground(int[] _arr_change)
        {
            foreach (int i in _arr_change)
            {
                DiemapButtonCollection[i].Background = new SolidColorBrush(Colors.Yellow);
            }
        }

        private void ChangeButtonEnabled(int[] _arr_change)
        {
            foreach (int i in _arr_change)
            {
                DiemapButtonCollection[i].Visibility = false;
                DiemapButtonCollection[i].IsEnabled = false;
            }
        }

그러면, 아래와 같이 변경된 속성이 UI에 반영이됩니다.

posted by Kanais
2021. 11. 2. 14:54 Programming/Error Clear!

참고 : https://stackoverflow.com/questions/17819613/visual-studio-2012-error-package-visual-c-package-failed-to-load

 

Visual Studio 2012 error: Package 'Visual C++ package' failed to load

When I'm trying to open any solutions that worked fine before in Visual Studio 2012, the error "Package 'Visual C++ package' failed to load" keeps showing up. And the solution can't be op...

stackoverflow.com

 

Visual 2013으로 개발하다가 위에 에러가 똭! 구글링을 통해 답을 찾았다.

 

  1. Visual Studio 를 실행한다.
  2. 메뉴에서 Tools를 선택하고 External Tools를 선택.
  3. External Tools 창에서, Add를 클릭하고 새로운 Contents를 생성.
  4. TitleCommand Prompt로 입력.
  5. Command 부분에 %comspec% 나 C:\Windows\System32\cmd.exe. 를 입력.
  6. Arguments 에는 현재 사용하고 있는 Visual Studio의 버전에 맞춰서 경로를 입력한다. "C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\Tools\VsDevCmd.bat" (전 Visual Studio 2013을 사용하므로 12.0 버전).
  7. Initial directory 에는 우측 버튼을 클릭하여 Project Directory을 선택해준다.
  8. 이제 OK 버튼만 누르면 끝.

그리고 나서.

  1. Visual Studio 아이콘을 우클릭해서 자세히 보기에 관리자 권한으로 실행!
  2. 이제 TOOLS → *Command Prompt** 를 선택해서 Command Prompt 창을 실행한다.
  3. 커맨드 창에 "devenv /Setup"을 입력!
  4. 그리고 Visual Studio를 다시 실행하면 잘 실행된다.
posted by Kanais