我有一个简单的树,它工作正常,但单击时不会突出显示,用户需要双击。
绑定到它的命令在单击时工作正常。
<TreeView ItemsSource="{Binding ElementsTypes}">
<TreeView.ItemTemplate>
<HierarchicalDataTemplate>
<TextBlock Text="{Binding Name}">
<TextBlock.InputBindings>
<MouseBinding Gesture="LeftClick"
Command="{Binding ElementsCommand}"
CommandParameter="{Binding}" />
</TextBlock.InputBindings>
</TextBlock>
</HierarchicalDataTemplate>
</TreeView.ItemTemplate>
</TreeView>
答案 0 :(得分:1)
那是因为你的import numpy as np
import matplotlib.pyplot as plt
from matplotlib.widgets import Slider
def update(val):
mv = smean.val
stdv = sstd.val
n_sample = round(sn.val)
nd = np.random.normal(loc=mv, scale=stdv, size=n_sample)
#Redraw histogram
ax.cla()
ax.hist(nd, normed=True, bins=n_bins0, alpha=0.5)
plt.draw()
def reset(event):
mv.reset()
stdv.reset()
n_sample.reset()
ax = plt.subplot(111)
plt.subplots_adjust(left=0.25, bottom=0.25)
m0 = -2.5
std0 = 1
n0 = 1000
n_bins0 = 20
nd = np.random.normal(m0, std0, n0)
plt.hist(nd, normed=True, bins=n_bins0, alpha=0.5)
axcolor = 'lightgray'
axmean = plt.axes([0.25, 0.01, 0.65, 0.03], axisbg=axcolor)
axstd = plt.axes([0.25, 0.06, 0.65, 0.03], axisbg=axcolor)
axssize = plt.axes([0.25, 0.11, 0.65, 0.03], axisbg=axcolor)
smean = Slider(axmean, 'Mean', -5, 5, valinit=m0)
sstd = Slider(axstd, 'Std', 0.1, 10.0, valinit=std0)
sn = Slider(axssize, 'n_sample', 10, 10000, valinit=n0)
smean.on_changed(update)
sstd.on_changed(update)
sn.on_changed(update)
plt.show()
“偷”了你的左键。一种可能的解决方案是将MouseBinding
属性添加到您的ViewModel并在IsSelected
上将其设置为true
:
ElementsCommand
通过这种方式,您还可以知道ViewModel中的哪个项目已被选中,并且能够以编程方式从ViewModel中操作选择。