阅读 54

WPF 中的DataTemplate 的嵌套

 

 

x:Class="WPF.MainWindow"

        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"

        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"

        xmlns:local="clr-namespace:WPF"

        mc:Ignorable="d"

        Title="MainWindow" Height="450" Width="800">

    

        x:Key="kk">

            

                

                    

                    

                

                

                Grid.Row="1" Height="50" Width="50" Fill="Red">

                

            

        

        x:Key="studentItemTemplate">

            

                Fill="Red" Width="200" Height="200">

            

        

        x:Key="studentJudgeTemplate">

            

                

                    

                    

                

                >this is template 222

                Grid.Row="1" ContentTemplate="{StaticResource studentItemTemplate}">

                

            

        

    

 

    

        ContentTemplate="{StaticResource studentJudgeTemplate}">

        

    

 

 

content presentor 的使用

------------------------------------------------------------

 

x:Class="WPF.Login"

             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" 

             xmlns:local="clr-namespace:WPF"

             mc:Ignorable="d" 

             d:DesignHeight="450" d:DesignWidth="800" x:Name="uc">

    

        x:Key="kk" TargetType="Label">

            Property="Template">

                

                    TargetType="Label">

                        

                            Margin="34,45,44,117" Fill="{TemplateBinding Background}"/>

                        

                    

                

            

        

    

 

    

        

            

            

        

        Grid.Row="0">111111111111

        Grid.Row="1" x:Name="lab" Content="{Binding MM}">

            

        

    

 

 

 

 

 

C# code

-------------------------

 public partial class Login : UserControl

    {

        public Login()

        {

            InitializeComponent();

            this.Loaded += Login_Loaded;

            this.DataContext = this;

        }

 

        private void Login_Loaded(object sender, RoutedEventArgs e)

        {

          

        }

        public static readonly DependencyProperty MMProperty = DependencyProperty.Register("MM", typeof(object), typeof(Login));

 

        public object MM

        {

            get { return (object)GetValue(MMProperty); }

            set { SetValue(MMProperty, value); }

 

        }

        private static bool setV(Object obj)

        {

            // lab.Content = obj;

            return true;

        }

    }

 

原文:https://www.cnblogs.com/bruce1992/p/14852697.html

文章分类
代码人生
版权声明:本站是系统测试站点,无实际运营。本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 XXXXXXo@163.com 举报,一经查实,本站将立刻删除。
相关推荐