簡體   English   中英

如何在.NET Windows應用程序中更改鼠標單擊觸發區域

[英]How to change mouse click trigger area in .NET Windows application

我有一些開發.NET Web應用程序的經驗,但是現在我在Windows應用程序上工作。 我在理解UI組件時遇到了麻煩。

特別是:有一個按鈕(下圖),其中只有文本是可單擊的,並且想要對其進行更改以應用於整個行(以藍色突出顯示)。

到目前為止,我發現單擊文本會在UI類ProbeTree.xaml.cs調用一個函數:

public partial class ProbeTree : UserControl
{
  private void StackPanel_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
   { etc.. }

然后從文件ProbeTree.gics調用此函數:

void System.Windows.Markup.IStyleConnector.Connect(int connectionId, object target) {
    switch (connectionId)
    {
    case 8:

    #line 189 "..\..\..\..\UI\Protocol\ProbeTree.xaml"
    ((System.Windows.Controls.StackPanel)(target)).PreviewMouseLeftButtonDown += new System.Windows.Input.MouseButtonEventHandler(this.StackPanel_PreviewMouseLeftButtonDown);

    #line default
    #line hidden
    break;
    }
}

似乎在此文件中,我應該獲得對整行的引用,並將鼠標單擊事件而不是當前target參數附加到該行。 不幸的是,我在這里一無所知,由於No symbols have been loaded for this document因此不會觸發此文件上的斷點。

最后, ProbeTree.xaml此代碼也相關:

<TreeView.Resources>
    ... many tags here ...
    <DataTemplate DataType="{x:Type xs:VMReading}">
        <StackPanel Orientation="Horizontal" DataContext="{Binding}"  PreviewMouseLeftButtonDown="StackPanel_PreviewMouseLeftButtonDown">
            <Label Content="{Binding Name}"></Label>
        </StackPanel>
    </DataTemplate>
</TreeView.Resources>

知道我如何實現目標嗎?

“名稱”文本是可單擊的

嘗試在堆棧面板上進行輸入綁定:

<StackPanel>    
    <StackPanel.InputBindings>
        <MouseBinding MouseAction="LeftClick" Command="{Binding MyCommand}" />
    </StackPanel.InputBindings>
</StackPanel

MyCommand在視圖模型中定義為System.Windows.Input.ICommand。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2025 STACKOOM.COM