zoukankan      html  css  js  c++  java
  • 怎样控制WPF GroupBox.HeaderTemplate中的控件

    http://www.cnblogs.com/masterfy/archive/0001/01/01/1527370.html

    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

  • 相关阅读:
    多个数字和数字字符串混合运算规则
    关于js对象引用的小例子
    实现函数 isInteger(x) 来判断 x 是否是整数
    写一个少于 80 字符的函数,判断一个字符串是不是回文字符串
    关于数组排序
    事件委托(事件代理)的原理以及优缺点是什么?
    将url的查询参数解析成字典对象
    js dom操作获取节点的一些方法
    js中arguments的应用
    深度克隆---js对象引用
  • 原文地址:https://www.cnblogs.com/swarb/p/9924326.html
Copyright © 2011-2022 走看看