当前位置: 首页>>代码示例>>C#>>正文


C# Control.GetValueSource方法代码示例

本文整理汇总了C#中System.Windows.Controls.Control.GetValueSource方法的典型用法代码示例。如果您正苦于以下问题:C# Control.GetValueSource方法的具体用法?C# Control.GetValueSource怎么用?C# Control.GetValueSource使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Windows.Controls.Control的用法示例。


在下文中一共展示了Control.GetValueSource方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TemplateApplyTest

        public void TemplateApplyTest()
        {
            string text = @"
            <ControlTemplate xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml' x:Name='root'>
                <FrameworkElement x:Name='child' Height='400'/>
                <ControlTemplate.Triggers>
                    <Trigger Property='FrameworkElement.Width' Value='100'>
                        <Setter Property='FrameworkElement.Height' Value='100'/>
                    </Trigger>
                    <Trigger Property='FrameworkElement.Width' Value='200'>
                        <Setter Property='FrameworkElement.Height' Value='200'/>
                        <Setter TargetName='child' Property='FrameworkElement.Height' Value='200'/>
                    </Trigger>
                    <EventTrigger RoutedEvent='FrameworkElement.Initialized'>
                        <Setter Property='FrameworkElement.Height' Value='300'/>
                    </EventTrigger>
                </ControlTemplate.Triggers>
            </ControlTemplate>";

            ControlTemplate controlTemplate = XamlLoader.Load(XamlParser.Parse(text)) as ControlTemplate;

            Control control = new Control();
            control.Width = 100;
            control.Template = controlTemplate;

            control.ApplyTemplate();

            Assert.AreEqual(1, control.VisualChildren.Count());

            FrameworkElement child1 = control.TemplateChild as FrameworkElement;
            Assert.IsNotNull(child1);

            FrameworkElement child2 = control.Template.FindName("child", control) as FrameworkElement;
            Assert.AreEqual(child1, child2);

            Assert.AreEqual(control, child1.TemplatedParent);
            Assert.AreEqual(400, child1.Height);
            Assert.AreEqual(BaseValueSource.ParentTemplate, child1.GetValueSource(FrameworkElement.HeightProperty).BaseValueSource);
            Assert.AreEqual(BaseValueSource.ParentTemplate, child1.GetBaseValueSource(FrameworkElement.HeightProperty));

            Assert.AreEqual(100, control.Height);
            Assert.AreEqual(BaseValueSource.TemplateTrigger, control.GetValueSource(FrameworkElement.HeightProperty).BaseValueSource);
            Assert.AreEqual(BaseValueSource.TemplateTrigger, control.GetBaseValueSource(FrameworkElement.HeightProperty));

            control.Width = 200;
            Assert.AreEqual(200, control.Height);
            Assert.AreEqual(BaseValueSource.TemplateTrigger, control.GetValueSource(FrameworkElement.HeightProperty).BaseValueSource);
            Assert.AreEqual(BaseValueSource.TemplateTrigger, control.GetBaseValueSource(FrameworkElement.HeightProperty));

            Assert.AreEqual(200, child1.Height);
            Assert.AreEqual(BaseValueSource.ParentTemplateTrigger, child1.GetValueSource(FrameworkElement.HeightProperty).BaseValueSource);
            Assert.AreEqual(BaseValueSource.ParentTemplateTrigger, child1.GetBaseValueSource(FrameworkElement.HeightProperty));

            control.RaiseEvent(new RoutedEventArgs(FrameworkElement.InitializedEvent, control));
            Assert.AreEqual(300, control.Height);
            Assert.AreEqual(BaseValueSource.TemplateTrigger, control.GetValueSource(FrameworkElement.HeightProperty).BaseValueSource);
            Assert.AreEqual(BaseValueSource.TemplateTrigger, control.GetBaseValueSource(FrameworkElement.HeightProperty));

            control.Template = null;
            control.ApplyTemplate();

            Assert.AreEqual(Double.NaN, control.Height);
        }
开发者ID:highzion,项目名称:Granular,代码行数:63,代码来源:FrameworkTemplateTest.cs

示例2: StyleEventTriggerTest

        public void StyleEventTriggerTest()
        {
            string text = @"
            <Style xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml' xmlns:test='clr-namespace:Granular.Presentation.Tests;assembly=Granular.Presentation.Tests'>
                <Setter Property='FrameworkElement.Width' Value='100'/>
                <EventSetter Event='FrameworkElement.Initialized' Handler='InitializedHandler'/>
                <Style.Triggers>
                    <EventTrigger RoutedEvent='FrameworkElement.Initialized'>
                        <Setter Property='FrameworkElement.Width' Value='200'/>
                    </EventTrigger>
                </Style.Triggers>
            </Style>";

            TestStyle style = new TestStyle();
            XamlLoader.Load(style, XamlParser.Parse(text));

            Control control = new Control();

            control.Style = style;
            Assert.AreEqual(100, control.Width);
            Assert.AreEqual(BaseValueSource.Style, control.GetValueSource(FrameworkElement.WidthProperty).BaseValueSource);
            Assert.AreEqual(0, style.InitializedHandlerCallsCount);

            control.RaiseEvent(new RoutedEventArgs(FrameworkElement.InitializedEvent, control));
            Assert.AreEqual(200, control.Width);
            Assert.AreEqual(BaseValueSource.StyleTrigger, control.GetValueSource(FrameworkElement.WidthProperty).BaseValueSource);
            Assert.AreEqual(1, style.InitializedHandlerCallsCount);

            control.Style = null;
            Assert.AreEqual(Double.NaN, control.Width);
            Assert.AreEqual(BaseValueSource.Default, control.GetValueSource(FrameworkElement.WidthProperty).BaseValueSource);

            control.RaiseEvent(new RoutedEventArgs(FrameworkElement.InitializedEvent, control));
            Assert.AreEqual(Double.NaN, control.Width);
            Assert.AreEqual(BaseValueSource.Default, control.GetValueSource(FrameworkElement.WidthProperty).BaseValueSource);
            Assert.AreEqual(1, style.InitializedHandlerCallsCount);
        }
开发者ID:diab0l,项目名称:Granular,代码行数:37,代码来源:StyleTest.cs


注:本文中的System.Windows.Controls.Control.GetValueSource方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。