2017-08-28 92 views
2

我用綁定項目源在WPF(C#)中定義了一個SplitButton。mahapps SplitButton點擊展開

僅當用戶單擊SplitButton右側的箭頭時,項目列表纔會展開。

如何在用戶點擊SplitButton區域時展開列表?

我試着處理click事件並設置屬性IsExpanded = true,但它會在一秒鐘後自動消失。

<Controls:SplitButton Name="SplitButton_Test" 
       Width="100" 
       HorizontalAlignment="Left" 
       HorizontalContentAlignment="Left" 
       ItemsSource="{Binding Dictionary_Test}" 
       DisplayMemberPath="Value" 
       SelectedValuePath="Key" 
       Click="Test_Click"> 
    <Controls:SplitButton.Icon> 
     <iconPacks:PackIconMaterial Margin="6" Kind="Alert" /> 
    </Controls:SplitButton.Icon> 
</Controls:SplitButton> 

private void Test_Click(object sender, RoutedEventArgs e) 
{ 
    if (SplitButton_Test.IsExpanded == false) 
    { 
     e.Handled = true; 
     SplitButton_Test.IsExpanded = true; //Doesn't work, closes automatically after 1 second 
    } 
} 

回答

0

這段代碼在MahApps正在關閉它:

//Make popup close even if no selectionchanged event fired (case when user select the save item as before) 
    void ListBoxPreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e) 
    { 
     var item = ContainerFromElement(_listBox, e.OriginalSource as DependencyObject) as ListBoxItem; 
     if (item != null) 
     { 
      IsExpanded = false; 
     } 
    } 

目前https://github.com/MahApps/MahApps.Metro/blob/develop/src/MahApps.Metro/MahApps.Metro.Shared/Controls/SplitButton.cs#L339

您需要刪除該事件處理程序。怎麼樣?這是另一個問題。

+0

謝謝!我怎樣才能徹底清除它? :) – daniol

+0

我不知道。我在這裏搜索,有問題和答案,但我沒有嘗試任何。一種方法是從源代碼構建MahApps並刪除該代碼。這實際上可能是最簡單的方法。 –