我写了下面的XAML代码。当鼠标悬停在按钮上时,我添加了样式代码来更改按钮的颜色。但是当悬停在按钮上时边框效果仍然存在,背景不会变为红色。请指教。
f1(10,2,100,5,10,1,5)
f1 <- function(n=10,m=2,priceinitial=100,delta=5,mean=10, sd=1, ninterval=5){
cat("I need to comment my code")
traders <- vector(mode="character", length=n)
traderscurrent <- vector(mode="character", length=n)
price <- vector(mode="numeric")
pricecurrent <- vector(mode="numeric")
for(nint in 1:ninterval)
{
L = floor(rnorm(1,mean,sd))
print(L)
x3 <- runif(2,0,1)
v <- c(0, min(x3), max(x3))
for(i in 1:n)
{
traders[i] <- runif(1,0,1)
if(findInterval(traders[i],v) == sample(c(1,3),1))
{
traders[i] <- "B"
}
else if(findInterval(traders[i],v) == 2)
{
traders[i] <- "N"
}
else {
traders[i] <- "S"
}
}
print(table(traders))
for(step in 1:L)
{
for(i in 1:n)
{
b <- sample(traders[-i], m)
print(b)
table(b)
traderscurrent[i] <- sample(b,1)
}
print(table(traderscurrent))
pricecurrent[step] = priceinitial+length(which(traderscurrent == "B"))*delta-length(which(traderscurrent == "S"))*delta
priceinitial = pricecurrent[step]
traders <- traderscurrent
#print(nint)
#print(step)
}
price <- c(price,pricecurrent)
price <- price[-step]
}
print(price)
plot(price)
}
f()
答案 0 :(得分:1)
您的代码几乎正常运行,请执行以下操作以使其完整:
BorderBrush
,Foreground
和Background
更改看起来像这样:
<Style x:Key="MyButtonStyle" TargetType="Button">
<Setter Property="OverridesDefaultStyle" Value="True"/>
<!--Sets the initial Foreground color-->
<Setter Property="Foreground" Value="White"/>
<!--Sets the initial Background color-->
<Setter Property="Background" Value="Gray"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Border Name="border"
BorderThickness="1"
Background="{TemplateBinding Background}">
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center" />
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="border" Property="BorderBrush" Value="Black" />
<Setter Property="Foreground" Value="Red"/>
<Setter Property="Background" Value="Green"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
按钮控制如下:
<Button Style="{StaticResource MyButtonStyle}" Content="Install"
Margin="150,30,30,22" Width="118" FontSize="18"
FontWeight="Bold" FontFamily="Segoe UI Light" FontStretch="ExtraExpanded" />