我有一個StackPanel兩個按鈕,我想改變一個人的背景和其他的前景,以相同的顏色。如何改變兩個按鈕顏色在一個StackPanel
我在XAML中嘗試這個。
<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>
LeftStackPanel
它只有位置參數,所以我不認爲這很重要。在profile_rct
我將背景綁定到BackgroundBtn
和profile_txt
我將同一個變量綁定到前景。在LeftButton
風格,沒有價值的前景。
在代碼在這裏是StackPanel_MouseEnter
和BackgroundBtn
代碼。
#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
private void StackPanel_MouseEnter(object sender, MouseEventArgs e)
{
Backgroundbtn = Brushes.CadetBlue;
}
有兩個問題在這裏,雖然我寫的事件上的StackPanel,項目的顏色只有當我指出來,只有尖銳物體的顏色變化而變化。我想改變兩個項目的顏色。
二是它不會改變profile_txt但背景的前景。我不明白這一點。