小编San*_*olo的帖子

何时隧道和冒泡事件在WPF中有用?

我知道冒泡和隧道是如何工作的.但是,我对使用它们很困惑.原因如下:

我想处理鼠标点击事件.泡沫它,有,MouseDown并且,隧道,有PreviewMouseDown.但是,MouseDown并不一定意味着用户点击了控件.可能是用户按下按钮并离开它以取消点击.如果没有点击按钮,我不想改变任何东西.

所以我的问题是,Bubbling/Tunneling策略有用吗?

c# wpf mouseevent event-bubbling mousedown

14
推荐指数
1
解决办法
8065
查看次数

Wpf 事件不冒泡

这是我的 XAML:

<Window x:Class="WpfApplication4.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow" Height="844.025" Width="678"  MouseUp="somethingClicked">
<Grid MouseUp="somethingClicked">
    <StackPanel MouseUp="somethingClicked" Margin="0,0,10,0">
    <Button x:Name="btnClickMe" Content="Click Me!" HorizontalAlignment="Left" VerticalAlignment="Top" Width="75" Margin="101,22,0,0" MouseUp="somethingClicked"/>
        <CheckBox x:Name="chkhandle" Content="CheckBox" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="241,28,0,0" RenderTransformOrigin="-0.588,1.188"/>
        <ListBox x:Name="lstEvents" HorizontalAlignment="Left" Height="604" VerticalAlignment="Top" Width="416" Margin="29,66,0,0"/>
    </StackPanel>
</Grid>
Run Code Online (Sandbox Code Playgroud)

这是 C# 代码:

namespace WpfApplication4
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
    protected int eventCounter = 0;

    public MainWindow()
    {
        InitializeComponent();
    }

    private void somethingClicked(object sender, RoutedEventArgs e)
    {
        eventCounter++; …
Run Code Online (Sandbox Code Playgroud)

c# wpf events

6
推荐指数
1
解决办法
5756
查看次数

如何从 Python 中的数据帧显示 wordcloud

目前,我有一个包含单词和权重 (tf*idf) 的数据框,我想显示在 wordcloud 中按权重排列的单词。

数据框位于左图。

def generate_wordcloud(words_tem):
    word_cloud = WordCloud(width = 512, height = 512, background_color='white', stopwords= None, max_words=20).generate(words_tem)
    plt.figure(figsize=(10,8),facecolor = 'white', edgecolor='blue')
    plt.imshow(word_cloud, interpolation='bilinear')
    plt.axis('off')
    plt.tight_layout(pad=0)
    plt.show()


tfidf = TfidfVectorizer(data, lowercase = False)
tfs = tfidf.fit_transform([data]) 

feature_names = tfidf.get_feature_names()

df = pd.DataFrame(tfs.T.toarray(), index=feature_names, columns= ['weight'])
df = df.sort_values(by = 'weight', ascending = False)
word_lists = df.index.values
unique_str  = ' '.join(word_lists)
print(df[0:20])
generate_wordcloud(unique_str)
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明

python nlp word-cloud

4
推荐指数
1
解决办法
6144
查看次数

标签 统计

c# ×2

wpf ×2

event-bubbling ×1

events ×1

mousedown ×1

mouseevent ×1

nlp ×1

python ×1

word-cloud ×1