2022.11.08.TIL
프리즘 강의:
https://www.youtube.com/watch?v=iTUy6AlyDgA
prism 기본 설정:
App.xaml.cs
public partial class App
{
protected override Window CreateShell()
{
return Container.Resolve<MainWindow>();
}
protected override void RegisterTypes(IContainerRegistry containerRegistry)
{
}
protected override void ConfigureModuleCatalog(IModuleCatalog moduleCatalog)
{
base.ConfigureModuleCatalog(moduleCatalog);
moduleCatalog.AddModule<MainModule>();
}
}
MainModule.cs
internal class MainModule : IModule
{
public void OnInitialized(IContainerProvider containerProvider)
{
var region = containerProvider.Resolve<IRegionManager>();
region.RegisterViewWithRegion("ContentRegion", typeof(Game));
}
public void RegisterTypes(IContainerRegistry containerRegistry)
{
}
}
쉬운 단축키(tab 두번 누르기):
propp: Property 생성
cmd: DelegateCommand 생성
public class UserInfoViewModel : BindableBase
{
public UserInfoViewModel()
{
}
private string _username;
public string UserName
{
get { return _username; }
set
{
SetProperty(ref _username, value);
//첫번째 방법
ClickCommand.RaiseCanExecuteChanged(); //클릭조건에 변경반영
}
}
private string _userAge;
public string UserAge
{
get { return _userAge; }
set
{
SetProperty(ref _userAge, value);
ClickCommand.RaiseCanExecuteChanged();
}
}
private DelegateCommand _clickCommand;
public DelegateCommand ClickCommand =>
_clickCommand ?? (_clickCommand = new DelegateCommand(ExecuteCommandName,CanExecute));
void ExecuteCommandName()
{
MessageBox.Show($"User name is : {UserName} and user age is : {UserAge}");
}
private bool CanExecute()
{
return !string.IsNullOrWhiteSpace(UserName) && !string.IsNullOrWhiteSpace(UserAge);
}
}
2번째 방법
public class UserInfoViewModel : BindableBase
{
public UserInfoViewModel()
{
}
private string _username;
public string UserName
{
get { return _username; }
set
{
SetProperty(ref _username, value);
}
}
private string _userAge;
public string UserAge
{
get { return _userAge; }
set
{
SetProperty(ref _userAge, value);
}
}
private DelegateCommand _clickCommand;
public DelegateCommand ClickCommand =>
_clickCommand ?? (_clickCommand = new DelegateCommand(ExecuteCommandName,CanExecute).ObservesProperty(()=>UserName).ObservesProperty(()=>UserAge));//ObervesProperty 사용
void ExecuteCommandName()
{
MessageBox.Show($"User name is : {UserName} and user age is : {UserAge}");
}
private bool CanExecute()
{
return !string.IsNullOrWhiteSpace(UserName) && !string.IsNullOrWhiteSpace(UserAge);
}
}
세 번째 방법
public class UserInfoViewModel : BindableBase
{
public UserInfoViewModel()
{
}
private string _username;
public string UserName
{
get { return _username; }
set
{
SetProperty(ref _username, value);
}
}
private string _userAge;
public string UserAge
{
get { return _userAge; }
set
{
SetProperty(ref _userAge, value);
}
}
private bool _isEnabled;
public bool IsEnabled
{
get { return _isEnabled; }
set { SetProperty(ref _isEnabled, value); }
}
private DelegateCommand _clickCommand;
public DelegateCommand ClickCommand =>
_clickCommand ?? (_clickCommand = new DelegateCommand(ExecuteCommandName).ObservesCanExecute(()=>IsEnabled));//IsEnabled 속성을 Binding해서 사용(checkbox)
void ExecuteCommandName()
{
MessageBox.Show($"User name is : {UserName} and user age is : {UserAge}");
}
private bool CanExecute()
{
return !string.IsNullOrWhiteSpace(UserName) && !string.IsNullOrWhiteSpace(UserAge);
}
}
Text="{Binding Path, UpdateSourceTrigger=PropertyChanged}" 이 속성이 있어야지 텍스트가 바뀔 때 마다 바인딩 적용
https://stopbyte.com/t/my-class-property-is-not-updated-from-textbox-text-binding-in-wpf/264/2
My Class Property is not updated from TextBox Text Binding in WPF
Here is a little hint @afree, I guess when writing into those TextBox’s you actually do it from the top most one and going down, thus the last one to get your changes is always the bottom most TextBox. Now can you try to do it in reverse, Write something
stopbyte.com
TextBox에 MaxLength속성이 있음
Binding 했을 때 value값을 검사하여 입력 제한을 할 수 있다.
엔터키로 입력받
https://chashtag.tistory.com/57
[C# WPF] MVVM패턴 TextBox Enter눌렀을 때 Command (KeyBinding)
안녕하세요. 오늘은 WPF MVVM패턴에서 TextBox에서 특정 버튼을 눌렀을 때 ViewModel의 함수로 연결하는 방법에 대해 알아보도록 하겠습니다. 우선 View입니다. 여기서 중요하게 보여야 할 부분은 두 가
chashtag.tistory.com
GotFocus, LostFocus 등 기능 Binding 하기:
How do I bind the LostFocus and GotFocus events to view model commands?
I am a new in C# and MVVM approach, I created such TextBox <TextBox x:Name="Tb_fps" Grid.Column="0" Text="{Binding FPS, UpdateSourceTrigger=PropertyChanged}" x:
stackoverflow.com
Visibility 속성 바인딩하기:
https://www.technical-recipes.com/2016/binding-the-visibility-of-wpf-elements-to-a-property/
Binding the visibility of WPF elements to a property - technical-recipes.com
How to set the visibility of your WPF user interface item so that it may be hidden/collapsed or shown as desiredStep 1: Create a new WPF ApplicationStep 2: Modify the MainWindow.xaml to create a User controlLet’s keep it simple – a button:Step 3: Creat
www.technical-recipes.com
프리즘 야구게임:
https://github.com/Rzreo/PrismBaseBallGame
GitHub - Rzreo/PrismBaseBallGame
Contribute to Rzreo/PrismBaseBallGame development by creating an account on GitHub.
github.com