출처: https://tip1234.tistory.com/214?category=842024
<StackPanel Orientation="Vertical">
<TextBlock Text="{Binding MYTXT}" Height="40" Margin="3" Background="AliceBlue"/>
<StackPanel Orientation="Horizontal">
<Button Content="Button01" Style="StaticResource MyBtnStyle}"/>
<Button Content="Button02" Style="StaticResource MyBtnStyle}"/>
<Button Content="Button03" Style="StaticResource MyBtnStyle}"/>
<Button Content="Button04" Style="StaticResource MyBtnStyle}"/>
<Button Content="Button05" Style="StaticResource MyBtnStyle}"/>
<Button Content="Button06" Style="StaticResource MyBtnStyle}"/>
</StackPanel>
</StackPanel>
public class MainViewModel : ViewModelBase
{
public string MYTXT { get; set; }
public MainViewModel()
{
MYTXT = "Button";
}
}
<StackPanel Orientation="Vertical">
<TextBlock Text="{Binding MYTXT}" Height="40" Margin="3" Background="AliceBlue"/>
<StackPanel Orientation="Horizontal">
<Button Content="Button01" Command="{Binding CmmandBtn01}" Style="StaticResource MyBtnStyle}"/>
<Button Content="Button02" Command="{Binding CmmandBtn02}" Style="StaticResource MyBtnStyle}"/>
<Button Content="Button03" Command="{Binding CmmandBtn03}" Style="StaticResource MyBtnStyle}"/>
<Button Content="Button04" Command="{Binding CmmandBtn04}" Style="StaticResource MyBtnStyle}"/>
<Button Content="Button05" Command="{Binding CmmandBtn05}" Style="StaticResource MyBtnStyle}"/>
<Button Content="Button06" Command="{Binding CmmandBtn06}" Style="StaticResource MyBtnStyle}"/>
</StackPanel>
</StackPanel>
public ICommand CmmandBtn01 { get; set; }
public ICommand CmmandBtn02 { get; set; }
public ICommand CmmandBtn03 { get; set; }
public ICommand CmmandBtn04 { get; set; }
public ICommand CmmandBtn05 { get; set; }
public ICommand CmmandBtn06 { get; set; }
public MainViewModel()
{
MYTXT = "Icon";
CmmandBtn01 = new RelayCommand(Btn01Click);
CmmandBtn02 = new RelayCommand(Btn02Click);
CmmandBtn03 = new RelayCommand(Btn03Click);
CmmandBtn04 = new RelayCommand(Btn04Click);
CmmandBtn05 = new RelayCommand(Btn05Click);
CmmandBtn06 = new RelayCommand(Btn06Click);
}
private void Btn01Click()
{
MYTXT = "Btn01"; RaisePropertyChanged("MYTXT");
}
private void Btn02Click()
{
MYTXT = "Btn02"; RaisePropertyChanged("MYTXT");
}
private void Btn03Click()
{
MYTXT = "Btn03"; RaisePropertyChanged("MYTXT");
}
private void Btn04Click()
{
MYTXT = "Btn04"; RaisePropertyChanged("MYTXT");
}
private void Btn05Click()
{
MYTXT = "Btn05"; RaisePropertyChanged("MYTXT");
}
private void Btn06Click()
{
MYTXT = "Btn06"; RaisePropertyChanged("MYTXT");
}