У меня странная проблема, у меня была страница WPF (с кодом C#) с некоторыми кнопками и событиями нажатия клавиш. Недавно я добавил элемент управления ленты, чтобы сгруппировать кнопки, и события нажатия клавиш больше не работают. Самое странное, что если я добавлю обратно любую из старых кнопок (вне ленты) и нажму на нее, то события нажатия клавиш начнут работать.
Спасибо
<Page x:Class="Ab3d.PowerToys.Samples.SceneEditor.SceneEditor"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:ribbon="clr-namespace:System.Windows.Controls.Ribbon;assembly=System.Windows.Controls.Ribbon"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:cameras="clr-namespace:Ab3d.Cameras;assembly=Ab3d.PowerToys"
xmlns:ab3d="clr-namespace:Ab3d.Controls;assembly=Ab3d.PowerToys"
xmlns:visuals="clr-namespace:Ab3d.Visuals;assembly=Ab3d.PowerToys"
xmlns:local="clr-namespace:Ab3d.PowerToys.Samples.SceneEditor"
mc:Ignorable="d"
d:DesignHeight="550" d:DesignWidth="800"
Title="SceneEditor" KeyDown="MainViewport_KeyDown" PreviewKeyDown="Window_PreviewKeyDown"
ShowsNavigationUI="False" >
<Page.Resources>
<BooleanToVisibilityConverter x:Key="VisibilityOfBool" />
<DiffuseMaterial x:Key="Material1" Brush ="Coral" />
</Page.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid Name="OptionsGrid" Grid.Row="0" Margin="0 0 0 10">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<!-- THE RIBBON -->
<ribbon:Ribbon SelectedIndex="0" KeyDown="MainViewport_KeyDown">
<!-- Tab -->
<RibbonTab Header="Model" HorizontalAlignment="Left" Height="88" VerticalAlignment="Top" Width="1000">
<!-- Draw -->
<RibbonGroup Header="Draw" Height="88" Margin="0" VerticalAlignment="Top" Width="280">
<RibbonButton x:Name="Point"
Label="Point"
LargeImageSource="C:\Users\Infra-Iordanescu\source\repos\ARES\Images\PointRo.png"
HorizontalAlignment="Left"
Height="60"
Margin="0,5,0,0"
VerticalAlignment="Top"
Width="20"
Click="NewPointButton_Click"/>
<RibbonButton x:Name="NewLine"
Label="Line"
LargeImageSource="C:\Users\Infra-Iordanescu\source\repos\ARES\Images\NewLine2.png"
HorizontalAlignment="Left"
Height="60"
Margin="0,5,0,0"
VerticalAlignment="Top"
Width="20"
Click="NewLineButton_Click"/>
<RibbonButton x:Name="Arc"
Label="Arc"
LargeImageSource="C:\Users\Infra-Iordanescu\source\repos\ARES\Images\Arc2.png"
HorizontalAlignment="Left"
Height="60"
Margin="0,5,0,0"
VerticalAlignment="Top"
Width="20"
Click="NewPointButton_Click"/>
<RibbonButton x:Name="Surface"
Label="Surface"
LargeImageSource="C:\Users\Infra-Iordanescu\source\repos\ARES\Images\Surface2.png"
HorizontalAlignment="Left"
Height="60"
Margin="0,5,0,0"
VerticalAlignment="Top"
Width="20"
Click="NewPointButton_Click"/>
<RibbonButton x:Name="Volume"
Label="Volume"
LargeImageSource="C:\Users\Infra-Iordanescu\source\repos\ARES\Images\Volume2.png"
HorizontalAlignment="Left"
Height="60"
Margin="0,5,0,0"
VerticalAlignment="Top"
Width="60"
Click="NewPointButton_Click"/>
<StackPanel>
<RibbonButton x:Name="Clothoid"
SmallImageSource="C:\Users\Infra-Iordanescu\source\repos\ARES\Images\Clothoid2.png"
HorizontalAlignment="Left"
Height="20"
Margin="0,5,0,0"
VerticalAlignment="Top"
Width="22"
Click="NewPointButton_Click"/>
<RibbonButton x:Name="Spline"
SmallImageSource="C:\Users\Infra-Iordanescu\source\repos\ARES\Images\Spline2.png"
HorizontalAlignment="Left"
Height="25"
Margin="0,0,0,0"
VerticalAlignment="Top"
Width="22"
Click="NewPointButton_Click"/>
<RibbonButton x:Name="Ellipse"
SmallImageSource="C:\Users\Infra-Iordanescu\source\repos\ARES\Images\Ellipse2.png"
HorizontalAlignment="Left"
Height="24"
Margin="0,0,0,0"
VerticalAlignment="Top"
Width="22"
Click="NewPointButton_Click"/>
</StackPanel>
</RibbonGroup>
<!-- Transform -->
<RibbonGroup Header="Transform" Height="88" Margin="0" VerticalAlignment="Top" Width="140">
<StackPanel>
<RibbonButton x:Name="Move"
Label="Move"
SmallImageSource="C:\Users\Infra-Iordanescu\source\repos\ARES\Images\Move.png"
HorizontalAlignment="Left"
Height="20"
Margin="0,0,0,0"
VerticalAlignment="Top"
Width="60"
Click="NewPointButton_Click"/>
<RibbonButton x:Name="Copy"
Label="Copy"
SmallImageSource="C:\Users\Infra-Iordanescu\source\repos\ARES\Images\Copy3.png"
HorizontalAlignment="Left"
Height="30"
Margin="0,0,0,0"
VerticalAlignment="Top"
Width="60"
Click="NewPointButton_Click"/>
<RibbonButton x:Name="Rotate"
Label="Rotate"
SmallImageSource="C:\Users\Infra-Iordanescu\source\repos\ARES\Images\Rotate2.png"
HorizontalAlignment="Left"
Height="20"
Margin="0,0,0,0"
VerticalAlignment="Top"
Width="60"
Click="NewPointButton_Click"/>
</StackPanel>
<StackPanel>
<RibbonButton x:Name="Mirror"
Label="Mirror"
SmallImageSource="C:\Users\Infra-Iordanescu\source\repos\ARES\Images\Mirror.png"
HorizontalAlignment="Left"
Height="20"
Margin="10,0,0,0"
VerticalAlignment="Top"
Width="60"
Click="NewPointButton_Click"/>
<RibbonButton x:Name="Scale"
Label="Scale"
SmallImageSource="C:\Users\Infra-Iordanescu\source\repos\ARES\Images\Scale.png"
HorizontalAlignment="Left"
Height="30"
Margin="10,0,0,0"
VerticalAlignment="Top"
Width="60"
Click="NewPointButton_Click"/>
<RibbonButton x:Name="Array"
Label="Array"
SmallImageSource="C:\Users\Infra-Iordanescu\source\repos\ARES\Images\Array.png"
HorizontalAlignment="Left"
Height="20"
Margin="10,0,0,0"
VerticalAlignment="Top"
Width="60"
Click="NewPointButton_Click"/>
</StackPanel>
</RibbonGroup>
<!-- Loads -->
<RibbonGroup Header="Loads" Height="88" Margin="0" VerticalAlignment="Top" Width="160">
<RibbonButton x:Name="Nodal"
Label="Nodal"
LargeImageSource="C:\Users\Infra-Iordanescu\source\repos\ARES\Images\NoadalLoads.png"
HorizontalAlignment="Left"
Height="60"
Margin="0,5,0,0"
VerticalAlignment="Top"
Width="50"
Click="NewPointButton_Click"/>
<RibbonButton x:Name="UDL"
Label="UDL"
LargeImageSource="C:\Users\Infra-Iordanescu\source\repos\ARES\Images\UDL.png"
HorizontalAlignment="Left"
Height="60"
Margin="0,5,0,0"
VerticalAlignment="Top"
Width="50"
Click="NewPointButton_Click"/>
<RibbonButton x:Name="Face"
Label="Face"
LargeImageSource="C:\Users\Infra-Iordanescu\source\repos\ARES\Images\Face.png"
HorizontalAlignment="Left"
Height="60"
Margin="0,5,0,0"
VerticalAlignment="Top"
Width="45"
Click="NewPointButton_Click"/>
</RibbonGroup>
<RibbonGroup Header="Analysis" Height="88" Margin="0" VerticalAlignment="Top" Width="100"/>
<RibbonGroup Header="Results" Height="88" Margin="0" VerticalAlignment="Top" Width="100"/>
<RibbonGroup Header="View" Height="88" Margin="0" VerticalAlignment="Top" Width="100"/>
</RibbonTab>
<RibbonTab Header="Prop" HorizontalAlignment="Left" Height="88" VerticalAlignment="Top" Width="798"/>
</ribbon:Ribbon>
<StackPanel Grid.Column="0" Orientation="Horizontal" Margin="10 0 0 0">
<!-- <StackPanel Orientation="Vertical">
<Button Name="ResetCameraCenterButton" Content="Reset camera" ToolTip="Sets camera TargetPosition to (0,0,0)" VerticalAlignment="Center" Click="ResetCameraCenterButton_Click" Margin="0 0 5 0"/>
<Button Name="FitViewButton" Content="Fit to view" Click="FitViewButton_Click" VerticalAlignment="Center" Margin="0 5 5 0" />
</StackPanel> -->
</StackPanel>
<!-- <StackPanel Grid.Column="1" Orientation="Vertical" Margin="10 0 0 0">
<Button Name="newPoint" Content="Point" ToolTip="New Point" VerticalAlignment="Center" Click="NewPointButton_Click" Margin="0 0 5 0"/>
<Button Name="newLine" Content="Line" ToolTip="New Line (L)" VerticalAlignment="Center" Click="NewLineButton_Click" Margin="0 5 5 0"/>
</StackPanel> -->
</Grid>
<Border Name="ViewportBorder" Grid.Row="1" Background="White"
MouseMove="ViewportBorder_MouseMove" >
<Viewport3D Name="MainViewport">
<ModelVisual3D x:Name="VisualSpace" />
<visuals:WireGridVisual3D x:Name="MainWireGrid"
CenterPosition="0 0 0"
Size="200 200"
WidthCellsCount="25"
HeightCellsCount="25"
LineColor="#555555"
LineThickness="1"
MajorLinesFrequency="5"
MajorLineThickness="2"
MajorLineColor="#333333"
IsVisible="{Binding Source={x:Static local:SceneEditorContext.Current}, Path=ShowWireGrid}" />
<ModelVisual3D x:Name="ObjectsVisual" />
</Viewport3D>
</Border>
<cameras:TargetPositionCamera Name="Camera1" Grid.Row="1"
TargetPosition="0 0 0"
Heading="30" Attitude="-30" Bank="0"
Distance="300"
ShowCameraLight="Always"
TargetViewport3D="{Binding ElementName=MainViewport}"/>
<ab3d:MouseCameraController Name="MouseCameraController1" Grid.Row="1"
ShowRotationCenterMarker="True"
ZoomMode="MousePosition"
RotateCameraConditions="RightMouseButtonPressed"
MoveCameraConditions="MiddleMouseButtonPressed"
EventsSourceElement="{Binding ElementName=ViewportBorder}"
TargetCamera="{Binding ElementName=Camera1}" />
<ab3d:CameraAxisPanel Grid.Row="1" VerticalAlignment="Bottom" HorizontalAlignment="Left"
TargetCamera="{Binding ElementName=Camera1}"
Visibility="{Binding Source={x:Static local:SceneEditorContext.Current}, Path=ShowCameraAxis, Converter={StaticResource VisibilityOfBool}}"/>
<ab3d:ViewCubeCameraController Grid.Row="1" VerticalAlignment="Bottom" HorizontalAlignment="Right"
TargetCamera="{Binding ElementName=Camera1}"
Visibility="{Binding Source={x:Static local:SceneEditorContext.Current}, Path=ShowViewCubeCameraController, Converter={StaticResource VisibilityOfBool}}" />
<ab3d:MouseCameraControllerInfo Name="MouseCameraControllerInfo1" Grid.Row="1" Margin="0 5 0 0"
VerticalAlignment="Top" HorizontalAlignment="Right"
MouseCameraController="{Binding ElementName=MouseCameraController1}"
Visibility="{Binding Source={x:Static local:SceneEditorContext.Current}, Path=ShowMouseCameraControllerInfo, Converter={StaticResource VisibilityOfBool}}" />
<!-- Selection canvas -->
<Canvas Name="SelectionOverlayCanvas" Grid.Column="0" IsHitTestVisible="False">
<Rectangle Name="SelectionRectangle" Fill="#555FD3FF" Stroke="#AA5FD3FF" StrokeThickness="1" Visibility="Collapsed" />
</Canvas>
<!-- Point data tooltip -->
<Canvas Name="DataToolTipCanvas" Grid.Column="0" IsHitTestVisible="False">
<Border Name="DataToolTipBorder" BorderThickness="2" BorderBrush="Black" Background="LightGray" Visibility="Collapsed">
<StackPanel Orientation="Vertical">
<TextBlock Text="Coordinates:" />
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding X, StringFormat={}X:{0:N}}"/>
<TextBlock Text="{Binding Y, StringFormat={} Y:{0:N}}"/>
<TextBlock Text="{Binding Z, StringFormat={} Z:{0:N}}"/>
</StackPanel>
</StackPanel>
</Border>
</Canvas>
</Grid>
</Page>
private void MainViewport_KeyDown(object sender, KeyEventArgs e)
{
System.Diagnostics.Debug.WriteLine("KeyDown");
// ESC deselects all
if (e.Key == Key.Escape)
{
for (var i = 0; i < spheres.Count; i++)
{
spheres[i].Material = material;
spheres[i].Radius = originalRadius;
}
for (var i = 0; i < lines.Count; i++)
{
lines[i].LineColor = originalLineColor;
}
DataToolTipBorder.Visibility = Visibility.Collapsed;
this.DataContext = null;
}