gpt4 book ai didi

c# - FocusManager.FocusedElement 在菜单中不起作用

转载 作者:行者123 更新时间:2023-12-03 10:31:35 26 4
gpt4 key购买 nike

我使用绑定(bind)将 FocusManager.FocusedElement 作为参数传递。

<Button Cursor="Hand" x:Name="NetworkModel" Width="Auto" Height="Auto" Background="Transparent" BorderBrush="Transparent" Foreground="#FF0398E2"
Command="{Binding Path=MenuSelectCommand}" CommandParameter="{Binding ElementName=root, Path=(FocusManager.FocusedElement)}">
<Grid Width="145">
<materialDesign:PackIcon Kind="GraphOutline" VerticalAlignment="Center"/>
<TextBlock HorizontalAlignment="Center" Text="Network Model" FontFamily="Champagne &amp; Limousines"/>
</Grid>
</Button>

它可以正常工作。现在我创建了菜单,但命令参数为空。有谁知道为什么不适用于菜单中的按钮,但仅适用于菜单外的按钮。
<Menu FontSize="14" VerticalAlignment="Center" Background="#FF303030" FontFamily="Champagne &amp; Limousines" Foreground="#FF0398E2" HorizontalAlignment="Center" Height="28" FontWeight="Bold">
<MenuItem Background="#FF303030" Height="28" Width="Auto">
<MenuItem.Header>
<Grid Width="Auto">
<materialDesign:PackIcon Kind="ViewGrid" VerticalAlignment="Center"/>
<TextBlock Width="Auto" Text="Summaries" VerticalAlignment="Center" HorizontalAlignment="Center" Margin="20,0,0,0"/>
</Grid>
</MenuItem.Header>
<Button Cursor="Hand" x:Name="SignalsSummary" Width="Auto" Height="Auto" Background="#FF303030" BorderBrush="Transparent" Foreground="#FF0398E2"
Command="{Binding Path=MenuSelectCommand}" CommandParameter="{Binding ElementName=root, Path=(FocusManager.FocusedElement)}">
<Grid Width="145">
<TextBlock HorizontalAlignment="Center" Text="Signals Summary" FontFamily="Champagne &amp; Limousines"/>
</Grid>
</Button>
<Button Cursor="Hand" x:Name="EventSummary" Width="Auto" Height="Auto" Background="#FF303030" BorderBrush="Transparent" Foreground="#FF0398E2"
Command="{Binding Path=MenuSelectCommand}" CommandParameter="{Binding ElementName=root, Path=(FocusManager.FocusedElement)}">
<Grid Width="145">
<TextBlock HorizontalAlignment="Center" Text="Event Summary" FontFamily="Champagne &amp; Limousines"/>
</Grid>
</Button>
<Button Cursor="Hand" x:Name="LoggesSummary" Width="Auto" Height="Auto" Background="#FF303030" BorderBrush="Transparent" Foreground="#FF0398E2"
Command="{Binding Path=MenuSelectCommand}" CommandParameter="{Binding ElementName=root, Path=(FocusManager.FocusedElement)}">
<Grid Width="145">
<TextBlock HorizontalAlignment="Center" Text="Logges Summary" FontFamily="Champagne &amp; Limousines"/>
</Grid>
</Button>
</MenuItem>
</Menu>

最佳答案

我没有解决为什么发送 null 但我改变了方法。我在每个按钮中添加了这个

    <i:Interaction.Triggers>
<i:EventTrigger EventName="PreviewMouseLeftButtonDown">
<i:CallMethodAction MethodName="OnMouseClick" TargetObject="{Binding}" />
</i:EventTrigger>
</i:Interaction.Triggers>

所以现在我有这个:
<Button Cursor="Hand" x:Name="LoggesSummary" Width="Auto" Height="Auto" Background="Transparent" BorderBrush="Transparent" Foreground="#FF0398E2">
<i:Interaction.Triggers>
<i:EventTrigger EventName="PreviewMouseLeftButtonDown">
<i:CallMethodAction MethodName="OnMouseClick" TargetObject="{Binding}" />
</i:EventTrigger>
</i:Interaction.Triggers>
<Grid Width="145">
<TextBlock HorizontalAlignment="Center" Text="Logges Summary" FontFamily="Champagne &amp; Limousines"/>
</Grid>
</Button>

关于c# - FocusManager.FocusedElement 在菜单中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60423621/

26 4 0