怎样控制WPF GroupBox.HeaderTemplate中的控件
2009-07-20 22:06
447 查看
Window1.xaml:
<Window x:Class="WpfApplication1.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300" Loaded="Window_Loaded">
<Grid>
<StackPanel>
<GroupBox Name="GroupBoxUC" MinHeight="100">
<GroupBox.HeaderTemplate>
<DataTemplate>
<DockPanel Name="dockbutton" HorizontalAlignment="Right">
<TextBlock Name="txtHeader" Text="header" Foreground="Red"/>
<Button MinHeight="20" Width="50" Content="后 退" Click="btnBack_Click" Name="btnBack"/>
<Button MinHeight="20" Width="50" Content="前 进" Click="btnForward_Click" Name="btnForward"/>
</DockPanel>
</DataTemplate>
</GroupBox.HeaderTemplate>
</GroupBox>
</StackPanel>
</Grid>
</Window>
------------------------------------------------------
Window1.xaml.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace WpfApplication1
{
/// <summary>
/// Window1.xaml 的交互逻辑
/// </summary>
public partial class Window1 : Window
{
private Button btnBack;
private Button btnForward;
private TextBlock txtheader;
public Window1()
{
InitializeComponent();
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
Border headborder = (Border)GroupBoxUC.Template.FindName("Header", GroupBoxUC);
ContentPresenter headContentPresenter = (ContentPresenter)headborder.Child;
DataTemplate datatemp = GroupBoxUC.HeaderTemplate;
txtheader = (TextBlock)datatemp.FindName("txtHeader", headContentPresenter);
btnBack = datatemp.FindName("btnBack", headContentPresenter) as Button;
btnForward = datatemp.FindName("btnForward", headContentPresenter) as Button;
}
private void btnBack_Click(object sender, RoutedEventArgs e)
{
txtheader.Text = "后退!";
btnBack.IsEnabled = false;
btnForward.IsEnabled = true;
}
private void btnForward_Click(object sender, RoutedEventArgs e)
{
txtheader.Text = "前进!";
btnForward.IsEnabled = false;
btnBack.IsEnabled = true;
}
}
}
------------------------------------------------------------------------------
源程序下载
资料:http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/d8fd2289-d8b9-447f-8d04-9557bd3ccda3
<Window x:Class="WpfApplication1.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300" Loaded="Window_Loaded">
<Grid>
<StackPanel>
<GroupBox Name="GroupBoxUC" MinHeight="100">
<GroupBox.HeaderTemplate>
<DataTemplate>
<DockPanel Name="dockbutton" HorizontalAlignment="Right">
<TextBlock Name="txtHeader" Text="header" Foreground="Red"/>
<Button MinHeight="20" Width="50" Content="后 退" Click="btnBack_Click" Name="btnBack"/>
<Button MinHeight="20" Width="50" Content="前 进" Click="btnForward_Click" Name="btnForward"/>
</DockPanel>
</DataTemplate>
</GroupBox.HeaderTemplate>
</GroupBox>
</StackPanel>
</Grid>
</Window>
------------------------------------------------------
Window1.xaml.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace WpfApplication1
{
/// <summary>
/// Window1.xaml 的交互逻辑
/// </summary>
public partial class Window1 : Window
{
private Button btnBack;
private Button btnForward;
private TextBlock txtheader;
public Window1()
{
InitializeComponent();
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
Border headborder = (Border)GroupBoxUC.Template.FindName("Header", GroupBoxUC);
ContentPresenter headContentPresenter = (ContentPresenter)headborder.Child;
DataTemplate datatemp = GroupBoxUC.HeaderTemplate;
txtheader = (TextBlock)datatemp.FindName("txtHeader", headContentPresenter);
btnBack = datatemp.FindName("btnBack", headContentPresenter) as Button;
btnForward = datatemp.FindName("btnForward", headContentPresenter) as Button;
}
private void btnBack_Click(object sender, RoutedEventArgs e)
{
txtheader.Text = "后退!";
btnBack.IsEnabled = false;
btnForward.IsEnabled = true;
}
private void btnForward_Click(object sender, RoutedEventArgs e)
{
txtheader.Text = "前进!";
btnForward.IsEnabled = false;
btnBack.IsEnabled = true;
}
}
}
------------------------------------------------------------------------------
源程序下载
资料:http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/d8fd2289-d8b9-447f-8d04-9557bd3ccda3
相关文章推荐
- 怎样控制WPF GroupBox.HeaderTemplate中的控件
- 潘鹏整理WPF(6)带标题的内容控件GroupBox&&Expander&&TabControl
- WPF控件之GroupBox
- 在WPF中获取DataGridTemplateColumn模板定义的内容控件
- WPF silverlight获取子控件(获取DataTemplate里的子控件)
- 在Repeater的HeaderTemplate和FooterTemplate模板中寻找控件
- 如何在后台代码获取控制EditItemTemplate的控件
- WPF-控件-ControlTemplate生成的控件
- c++ builder GroupBox的使用方法,如何把控件拖到TGroupBox上面
- mfc evc CheckBox控件被Group Box控件给遮盖
- c#GroupBox控件添加右键菜单
- WPF中的ControlTemplate(控件模板)
- 自行实现透明的控件如Panel GroupBox
- mfc static,checkbox,groupbox,redio 控件透明
- WPF备忘录(5)怎样修改模板中的控件
- wpf日历控件制作过程分析(1)---定义header
- c# + linq 判定GroupBox上的所有TextBox控件的Text为空
- WPF Template模版之寻找失落的控件【三】
- 请问怎么在VC++中,怎样控制控件的TAB键顺序?
- 怎样控制界面控件之进度条(ProgressBar)功能