现在我想在表单的剩余空白部分显示点击事件[如gridview或listview],就像在web应用程序中一样,我们可以使用内容占位符来显示点击事件...问题是我可以找不到合适的选择... [我不喜欢mdi形式] ..所以任何建议都会有所帮助......到目前为止,我的代码如下,[所有的clickevents都在我的cs上页面和工作正常,所以不包括在内]
<Window x:Class="WpfApplication1.EFSHome"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="EFSHome" Height="300" Width="300">
<Window.Resources>
<Style x:Key="MyBorderStyle" TargetType="Border">
<Setter Property="BorderBrush" Value="Cornsilk" />
</Style>
<Style x:Key="btnStyle" TargetType="Button">
<Setter Property="Background" Value="Cornsilk" />
</Style>
</Window.Resources>
<Grid Name="grid0">
<Grid.RowDefinitions>
<RowDefinition Height="30*" />
<RowDefinition Height="234*" />
</Grid.RowDefinitions>
<Image x:Name="img" Source="everest.jpg" Stretch="Fill" Grid.RowSpan="2">
</Image>
<Grid Name="grid1" Margin="0">
<StackPanel Orientation="Vertical" Background="Transparent">
<StackPanel Orientation="Horizontal" Name="panel1"
VerticalAlignment="Top" Margin="3">
<Button Style="{StaticResource btnStyle}" Content="RMS Entry" Name="btn_RMS_Entry"
ContextMenuService.IsEnabled="False" Click="btn_RMS_Entry_Click">
<Button.ContextMenu>
<ContextMenu Background="Transparent">
<MenuItem Header="Shipment"/>
<MenuItem Header="Order"/>
<MenuItem Header="LC"/>
<MenuItem Header="BL"/>
</ContextMenu>
</Button.ContextMenu>
</Button>
<Button Style="{StaticResource btnStyle}" Content="RMS Payment" Name="btn_RMS_P"></Button>
</StackPanel>
</StackPanel>
<Grid Name="grid2" Margin="3,30,0,7">
<StackPanel Orientation="Horizontal" Name="panel3"
VerticalAlignment="Top" Margin="0,3,0,5" Height="35">
<Button Style="{StaticResource btnStyle}" Content="Edit" Name="btn_Edit" />
<Button Style="{StaticResource btnStyle}" Content="emp_list" Name="btn_Emp"/>
<Button Style="{StaticResource btnStyle}" Content="Exit" Name="btn_Exit" Click="btn_Exit_Click" />
</StackPanel>
</Grid>
</Grid>
</Grid>
</Window>
答案 0 :(得分:0)
根据您分享的Xaml,很难准确理解您尝试完成的内容。但是,我已将您的布局简化为以下内容:
<Window x:Class="DisplayClickEventsResponse.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="EFSHome" Height="300" Width="300">
<Window.Resources>
<Style TargetType="Button">
<Setter Property="Background" Value="Cornsilk" />
</Style>
</Window.Resources>
<DockPanel>
<StackPanel DockPanel.Dock="Top" Orientation="Horizontal">
<Button Click="Button_Click" Content="RMS Entry"></Button>
<Button Click="Button_Click" Content="RMS Payment"></Button>
<Button Click="Button_Click" Content="Edit"></Button>
<Button Click="Button_Click" Content="Emp_list"></Button>
<Button Click="Button_Click" Content="Exit"></Button>
</StackPanel>
<ListBox x:Name="theListBox" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"></ListBox>
</DockPanel>
</Window>
在后面的代码中,Button_Click处理程序如下所示:
private void Button_Click(object sender, RoutedEventArgs e)
{
theListBox.Items.Add(string.Format("The button {0} was clicked", ((Button)sender).Content));
}
为简单起见,我选择为每个按钮使用相同的Click事件处理程序。处理程序只是将作为项添加的字符串格式化为ListBox。我删除了MyBorderStyle样式,因为布局不包含Borders。我使用了一个更简单的DockPanel,以便让按钮位于顶部(使用StackPanel)并使用ListBox(占用剩余空间)来显示Click事件。
我希望这会有所帮助。