gpt4 book ai didi

c# - 在禁用的 WPF StackPanel 中处理单击事件或 MouseDown

转载 作者:太空宇宙 更新时间:2023-11-03 11:03:53 25 4
gpt4 key购买 nike

我尝试做类似的事情已经有一段时间了,现在我准备抛出一个 NotImplementedException……我的意思是,认输。你是我最后的希望。

因此,我的目标是:出于用户友好的目的,在用户单击它时启用 StackPanel。

我在这个禁用的 StackPanel 中有一些项目,它位于 Window 内的 Grid 内的 ScrollViewer 内。

有一段我的代码可以理解:

<Grid x:Name="MainGrid">
<Grid.RowDefinitions>
<RowDefinition MinHeight="30" MaxHeight="30"/>
<RowDefinition MinHeight="22" MaxHeight="22"/>
<RowDefinition MinHeight="155" Height="155"/>
<RowDefinition MinHeight="130"/>
<RowDefinition MinHeight="25" MaxHeight="25"/>
<RowDefinition MinHeight="22" MaxHeight="22"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition MinWidth="355" Width="360" />
<ColumnDefinition MinWidth="330" />
<ColumnDefinition MinWidth="280" />
</Grid.ColumnDefinitions>
<ScrollViewer Grid.Column="2" Grid.Row="3" VerticalScrollBarVisibility="Auto">
<StackPanel IsEnabled="False" IsEnabledChanged="ioStackPanel_IsEnabledChanged">
<Grid Height="22">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="110"/>
<ColumnDefinition/>
<ColumnDefinition Width="50"/>
<ColumnDefinition Width="50"/>
<ColumnDefinition Width="20"/>
</Grid.ColumnDefinitions>
</Grid>
</StackPanel>
</ScrollViewer>
</Grid>

我已经尝试过类似的东西了:

<ScrollViewer Grid.Column="2" Grid.Row="3" VerticalScrollBarVisibility="Auto" MouseDown="ScrollViewer_MouseDown">

private void ScrollViewer_MouseDown(object sender, MouseButtonEventArgs e)
{
MessageBox.Show("Well done bro!");
}

但没有提出任何意见。没有显示 MessageBox。

最佳答案

下面的代码工作正常,照着做。

<Grid x:Name="MainGrid">
<Grid.RowDefinitions>
<RowDefinition MinHeight="30" MaxHeight="30" />
<RowDefinition MinHeight="22" MaxHeight="22" />
<RowDefinition Height="155" MinHeight="155" />
<RowDefinition MinHeight="130" />
<RowDefinition MinHeight="25" MaxHeight="25" />
<RowDefinition MinHeight="22" MaxHeight="22" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="360" MinWidth="355" />
<ColumnDefinition MinWidth="330" />
<ColumnDefinition MinWidth="280" />
</Grid.ColumnDefinitions>
<ScrollViewer Grid.Row="3"
Grid.Column="2"
PreviewMouseLeftButtonDown="InnerPanel_PreviewMouseLeftButtonDown_1"
VerticalScrollBarVisibility="Auto">
<StackPanel Name="InnerPanel"
Background="Gray"
IsEnabled="False"
IsEnabledChanged="StackPanel_IsEnabledChanged_1">
<Grid>

<Grid.ColumnDefinitions>
<ColumnDefinition Width="110" />
<ColumnDefinition />
<ColumnDefinition Width="50" />
<ColumnDefinition Width="50" />
<ColumnDefinition Width="20" />
</Grid.ColumnDefinitions>
<Button Grid.Column="2" Content="Inner Panel" />
</Grid>
</StackPanel>
</ScrollViewer>
</Grid>


private void InnerPanel_PreviewMouseLeftButtonDown_1(object sender, MouseButtonEventArgs e)
{

}

这工作正常并在上述事件中实现您的逻辑。

关于c# - 在禁用的 WPF StackPanel 中处理单击事件或 MouseDown,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16689938/

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