gpt4 book ai didi

mahapps.metro - mahapps SplitButton 单击展开

转载 作者:行者123 更新时间:2023-12-03 03:39:24 34 4
gpt4 key购买 nike

我在 WPF(C#) 中定义了一个带有绑定(bind)项源的 SplitButton。

只有当用户单击 SplitButton 右侧的箭头时,项目列表才会展开。

当用户点击SplitButton区域时如何展开列表?

我尝试处理点击事件并设置属性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
}
}

最佳答案

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

您需要删除该事件处理程序。如何?这完全是另一个问题。

关于mahapps.metro - mahapps SplitButton 单击展开,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45916864/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com