2017-12-27 1032 views
0

我有一個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我將背景綁定到BackgroundBtnprofile_txt我將同一個變量綁定到前景。在LeftButton風格,沒有價值的前景。

在代碼在這裏是StackPanel_MouseEnterBackgroundBtn代碼。

#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但背景的前景。我不明白這一點。

回答

0

脫穎而出的第一件事是萬一區別:BackgroundBtn不是在您的視圖模型的屬性,但Backgroundbtn是。

是這個問題?

相關問題