我有这个片段:
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:external="clr-namespace:ToggleSwitch;assembly=ToggleSwitch"
xmlns:modern="clr-namespace:Tools.Views.New_Project"
xmlns:Controls="clr-namespace:Assergs.Windows.Controls;assembly=Assergs.Windows"
x:Class="Tools.FirstInterface"
Title="Nouveau projet" Height="Auto" Width="Auto"
WindowStyle="None"
>
<Grid >
<DockPanel>
<Grid DockPanel.Dock="Bottom" Height="38" VerticalAlignment="Bottom" Background="LightGray" >
<Button Content="Annuler" Background="White" HorizontalAlignment="Right" Width="80" Height="22" VerticalAlignment="Bottom" Margin="0,0,0,8" BorderBrush="CadetBlue" BorderThickness="2" FontWeight="Bold" FontFamily="Times New Roman" />
<Button Content="Suivant >>" Background="#FFF9F7F7" Margin="0,0,94,8" HorizontalAlignment="Right" Width="81" Height="22" VerticalAlignment="Bottom" RenderTransformOrigin="0.5,0" BorderBrush="CadetBlue" BorderThickness="2" FontFamily="Times New Roman" FontWeight="Bold" Click="Button_Click_4"/>
<Button Content="<< Précédent" Background="White" Margin="0,0,180,8" HorizontalAlignment="Right" Width="82" Height="22" VerticalAlignment="Bottom" BorderBrush="CadetBlue" BorderThickness="2" FontFamily="Times New Roman" FontWeight="Bold"/>
</Grid>
<UserControl x:Name="container"></UserControl>
</DockPanel>
</Grid>
</Window>
问题是网格中的按钮不可点击!!!即使我在后面的代码中添加此方法:
private void Button_Click_4(object sender, RoutedEventArgs e)
{
MessageBox.Show("hello world!!");
}
当我点击按钮时没有任何反应。
修改 我认为问题来自用户控制
<UserControl x:Class="Tools.Views.New_Project.TypeOfProject"
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:d="http://schemas.microsoft.com/expression/blend/2008"
>
<Grid >
<DockPanel HorizontalAlignment="Left" Width="2132" Margin="0,0,-1163,-684" Height="828" VerticalAlignment="Top" >
<Expander Header="Positionnement" VerticalAlignment="Top" DockPanel.Dock="Left" BorderThickness="4" Margin="0,10,0,0" FontWeight="Bold" FontStyle="Italic" FontSize="14" FontFamily="Times New Roman">
<DockPanel>
<Label Height="28" Margin="10,10,10,0" Cursor="Hand" Content="Positionnement 2D" DockPanel.Dock="Top" MouseDoubleClick="Label_MouseDoubleClick_1" MouseUp="Label_MouseDoubleClick_1" FontWeight="Normal" FontStyle="Italic" FontSize="12" FontFamily="Times New Roman"/>
<Label Height="28" Margin="10,10,10,0" Cursor="Hand" Content="Positionnement 3D" DockPanel.Dock="Bottom" MouseDoubleClick="Label_MouseDoubleClick_2" MouseUp="Label_MouseDoubleClick_2" FontWeight="Normal" FontStyle="Italic" FontSize="12" FontFamily="Times New Roman"/>
</DockPanel>
</Expander>
</DockPanel>
<DockPanel HorizontalAlignment="Left" Width="2132" Margin="0,113,-1163,-729" Height="760" VerticalAlignment="Top" >
<Expander Header="Métrologie" VerticalAlignment="Top" DockPanel.Dock="Left" BorderThickness="4" Margin="0,10,0,0" FontFamily="Times New Roman" FontSize="14" FontWeight="Bold" FontStyle="Italic">
<DockPanel>
<Label Height="28" Margin="10,10,10,0" Cursor="Hand" Content="Métrologie1D" DockPanel.Dock="Bottom" MouseDoubleClick="Label_MouseDoubleClick_3" MouseUp="Label_MouseDoubleClick_3" FontWeight="Normal" FontStyle="Italic" FontSize="12" FontFamily="Times New Roman"/>
<Label Height="28" Margin="10,10,10,0" Cursor="Hand" Content="Métrologie2D" DockPanel.Dock="Bottom" MouseDoubleClick="Label_MouseDoubleClick_3" MouseUp="Label_MouseDoubleClick_3" FontWeight="Normal" FontStyle="Italic" FontSize="12" FontFamily="Times New Roman"/>
</DockPanel>
</Expander>
</DockPanel>
<DockPanel HorizontalAlignment="Left" Width="2138" Margin="-119,220,-1050,-875" Height="799" VerticalAlignment="Top" >
<Expander Header="Classification" BorderThickness="4" Margin="0,10,0,0" HorizontalAlignment="Right" Width="2016" FontFamily="Times New Roman" FontSize="14" FontWeight="Bold" FontStyle="Italic" Height="234" VerticalAlignment="Top" IsExpanded="True">
</Expander>
</DockPanel>
<GroupBox Header="" Height="182" VerticalAlignment="Top" Margin="219,38,0,-76" HorizontalAlignment="Left" Width="402"/>
<Label Margin="248,79,-66,31" Cursor="Hand" Content="Algorithme1" DockPanel.Dock="Right" x:Name="algo1"/>
<Label Margin="248,161,-61,-47" Cursor="Hand" Width="Auto" Content="Algorithme2" DockPanel.Dock="Right" x:Name="algo2" />
<Label Margin="248,118,-66,-12" Cursor="Hand" Width="Auto" Content="Algorithme3" DockPanel.Dock="Right" x:Name="algo3"/>
<GroupBox Header="Présentation de type du programme" Height="182" VerticalAlignment="Top" Margin="621,38,0,-76" FontWeight="Bold" FontStyle="Italic" FontSize="14" FontFamily="Times New Roman"/>
<Label Content="dddddd" Margin="626,76,0,-76"/>
<GroupBox Header="" Margin="219,220,0,-280" Height="204" VerticalAlignment="Top">
<Label Content="Nom: " HorizontalAlignment="Left" Height="29" VerticalAlignment="Top" Width="87" Margin="0,39,0,0"/>
</GroupBox>
<Label Content="Emplacement: " HorizontalAlignment="Left" Height="35" VerticalAlignment="Top" Width="99" Margin="224,330,0,-221"/>
<TextBox Margin="321,276,243,-155" Height="23" VerticalAlignment="Top"/>
<TextBox Margin="323,330,241,-209" Height="23" VerticalAlignment="Top"/>
<Button Name="browser" Content="Parcourir...." Height="23" VerticalAlignment="Top" Margin="774,330,108,-209"/>
</Grid>
</UserControl>
答案 0 :(得分:1)
此代码工作正常。如有任何错误,请重新检查您的代码。我测试了你的代码,它运行良好。可能还有其他一些问题。我还有其他的代码。??