我有一个带有撤消图像的按钮。 我希望按钮在用户点击(按下)按钮时显示边框。
# Reproduce dataset
obs <- c(8.12903225806452, 4.65483870967742, 4.00967741935484, 2.82903225806452,
1.02258064516129, 4.94838709677419, 2.03548387096774, 4.56129032258065,
6.66451612903226, 10.4129032258065, 3.7741935483871, 9.93870967741936)
uncorrected <- structure(list(CanESM2 = c(3.71099209785461, 6.68828105926514,
4.2675461769104, 4.29092979431152, 6.47999143600464, 6.30958032608032,
3.28256869316101, 1.06898427009583, 4.01592206954956, 7.88787031173706,
10.8663206100464, 9.14756298065186), GFDL.ESM2M = c(4.56643295288086,
8.36136913299561, 4.6934700012207, 4.62750291824341, 6.34791326522827,
0.916408598423004, 0.111764870584011, 0.570569038391113, 3.05491662025452,
3.29908037185669, 5.98263263702393, 7.52161026000977), MRI.CGCM3 = c(3.94400858879089,
2.48861312866211, 0.663281202316284, 0.422377318143845, 1.49548053741455,
1.8869035243988, 5.35201597213745, 3.94722390174866, 5.0041446685791,
6.11909627914429, 6.37435054779053, 5.9401068687439), NorESM1.M = c(8.83542060852051,
8.36209106445312, 3.22844076156616, 2.86131143569946, 2.05858564376831,
2.39689040184021, 1.06175291538239, 1.03921580314636, 2.49208211898804,
6.83605766296387, 7.95251750946045, 4.8852391242981), inmcm4 = c(5.88600730895996,
8.03514385223389, 3.86212635040283, 1.51728367805481, 3.46821308135986,
1.30993270874023, 0.497318655252457, 0.589299857616425, 1.63358855247498,
3.61927103996277, 4.99840354919434, 10.5596942901611)), .Names = c("CanESM2",
"GFDL.ESM2M", "MRI.CGCM3", "NorESM1.M", "inmcm4"), class = "data.frame", row.names = c(NA,
-12L))
corrected <- structure(list(CanESM2 = c(4.69295692443848, 6.2362003326416,
4.48602199554443, 4.21368360519409, 6.02497625350952, 5.94498348236084,
3.92529225349426, 1.07059073448181, 3.92306709289551, 8.00215721130371,
10.9688482284546, 9.95723056793213), GFDL.ESM2M = c(6.74847173690796,
10.7781000137329, 6.89084196090698, 7.5780816078186, 8.96726703643799,
3.57111501693726, 1.20403492450714, 2.76221370697021, 4.98387718200684,
5.27927255630493, 8.87845706939697, 9.95864582061768), MRI.CGCM3 = c(5.45173072814941,
3.37272930145264, 2.20000958442688, 1.12101686000824, 2.67246603965759,
3.10278224945068, 6.02392053604126, 4.70185708999634, 5.86025190353394,
6.41299057006836, 7.1956262588501, 7.59840393066406), NorESM1.M = c(9.49540519714355,
9.88559532165527, 4.86537599563599, 4.56189870834351, 3.85974431037903,
4.07706260681152, 2.55634951591492, 2.63215637207031, 4.21092081069946,
7.66422271728516, 8.75070095062256, 5.95497798919678), inmcm4 = c(8.21576976776123,
11.1972188949585, 6.08181619644165, 3.58428621292114, 5.543297290802,
3.46666693687439, 1.88991332054138, 1.94812619686127, 3.71879911422729,
5.70409107208252, 6.85269260406494, 11.8774194717407)), .Names = c("CanESM2",
"GFDL.ESM2M", "MRI.CGCM3", "NorESM1.M", "inmcm4"), class = "data.frame", row.names = c(NA,
-12L))
# Create layout
m <- cbind(c(1,5,9), c(2,6,10), c(3,7,9), c(4,8,10))
layout(m)
# Plot
for (i in 1:length(names(uncorrected))) {
# Plot uncorrected vs obs
qqplot(as.vector(obs), uncorrected[,i], xlim=c(0,14), ylim=c(0,14),
xlab=expression("Obs. precip." ~ (mm ~ day^{-1})),
ylab=expression("Mod. precip." ~ (mm ~ day^{-1})))
abline(0, 1)
# Then plot corrected vs obs
qqplot(as.vector(obs), corrected[,i], xlim=c(0,14), ylim=c(0,14),
xlab=expression("Obs. precip." ~ (mm ~ day^{-1})),
ylab=expression("Mod. precip." ~ (mm ~ day^{-1})))
abline(0, 1)
}
但它根本不起作用。 任何帮助将不胜感激!
答案 0 :(得分:0)
它不起作用,因为按钮模板直接将边框粗细设置为1,忽略按钮元素本身的边框粗细属性。您正在成功更改未使用的值。
如果要更改边框粗细,则必须复制和修改按钮模板。
答案 1 :(得分:0)
我对你的风格进行了以下更改:1)在ControlTemplate
内移动了触发器; 2)将x:Name
分配给Border
,以便在触发器中引用它; 3)定义BorderBrush
。
<Button Margin="0" HorizontalAlignment="Center" Height="25" Width="75" VerticalAlignment="Center">
<Button.Style>
<Style TargetType="{x:Type Button}">
<Setter Property="Background" Value="White"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Border x:Name="b0" Background="{TemplateBinding Background}">
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsPressed" Value="True">
<Setter Property="BorderThickness" TargetName="b0" Value="1"/>
<Setter Property="BorderBrush" TargetName="b0" Value="Blue"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Button.Style>
<Image Grid.Column="0" Grid.Row="0" Margin="0,0,0,0" Height="20" Width="20" Source="/Images/Undo.jpg">
<Image.Style>
<Style TargetType="Image">
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Opacity" Value="0.7"/>
</Trigger>
</Style.Triggers>
</Style>
</Image.Style>
</Image>
</Button>