스택 패널에 두 개의 버튼이 있으며 배경색과 다른 색상의 전경색을 같은 색상으로 변경하고 싶습니다.스택 패널에서 두 개의 버튼 색상을 변경하는 방법
나는 이것을 xaml에서 시도했다. LeftStackPanel
에서
<StackPanel
Style="{DynamicResource LeftStackPanel}"
MouseEnter="StackPanel_MouseEnter"
MouseLeave="StackPanel_MouseLeave"
>
<Button
x:Name="profile_rct"
HorizontalAlignment="Center"
Height="70"
VerticalAlignment="Center"
Width="7"
Background="{Binding
Path=BackgroundBtn,
Mode=OneWay}"
BorderThickness="1,1,1,1"
BorderBrush="DimGray" />
<Button
x:Name="profile_txt"
Content="Profil Bilgisi"
Style="{DynamicResource LeftButton}"
Foreground="{Binding
Path=BackgroundBtn,
Mode=OneWay}">
<Button.LayoutTransform>
<RotateTransform Angle="90" />
</Button.LayoutTransform>
</Button>
</StackPanel>
는 위치 인수가 있습니다 만, 그래서 나는 그것이 중요하다고 생각하지 않습니다. profile_rct
에서 배경을 BackgroundBtn
에 바인드하고 profile_txt
에 전 이번에는 동일한 변수를 전경에 바인딩합니다. LeftButton
스타일에는 전경 값이 없습니다.
여기 코드는 StackPanel_MouseEnter
및 BackgroundBtn
코드입니다. 두 가지 문제는 내가 그들을 가리켜 만 뾰족한 항목의 색상이 변경 될 때 항목의 색상 만 변경 StackPanel의에서 이벤트를 쓰기도하지만, 여기가
private void StackPanel_MouseEnter(object sender, MouseEventArgs e)
{
Backgroundbtn = Brushes.CadetBlue;
}
#region ViewModelProperty
private Brush backgroundbtn;
public Brush Backgroundbtn
{
get
{
return backgroundbtn;
}
set
{
backgroundbtn = value;
OnPropertyChanged("Backgroundbtn");
}
}
private void OnPropertyChanged(string v)
{
//throw new NotImplementedException();
}
#endregion
있습니다. 두 항목의 색상을 변경하고 싶습니다.
두 번째는 profile_txt의 전경을 변경하지 않고 배경을 변경하는 것입니다. 나는 그것을 이해하지 못했다. BackgroundBtn
이 당신의 ViewModel의 속성이 아니라 Backgroundbtn
은 다음과 같습니다
Background="{Binding ElementName=BackgroundBtn, Path=Background, Mode=OneWay}"