Exemplo n.º 1
0
        public void StyleDataTriggerTest()
        {
            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'/>
                <Style.Triggers>
                    <DataTrigger Binding='{Binding DoubleValue}' Value='1'>
                        <Setter Property='FrameworkElement.Width' Value='200'/>
                    </DataTrigger>
                </Style.Triggers>
            </Style>";

            TestStyle style = new TestStyle();

            XamlLoader.Load(style, XamlParser.Parse(text));

            Control control = new Control();

            BindingTestDataContext dataContext = new BindingTestDataContext();

            dataContext.DoubleValue = 1;

            control.Style = style;

            Assert.AreEqual(100, control.Width);

            control.DataContext = dataContext;

            Assert.AreEqual(200, control.Width);

            dataContext.DoubleValue = 2;

            Assert.AreEqual(100, control.Width);

            dataContext.DoubleValue = 1;

            Assert.AreEqual(200, control.Width);

            control.DataContext = null;

            Assert.AreEqual(100, control.Width);
        }
Exemplo n.º 2
0
        public void StyleDataTriggerTest()
        {
            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'/>
                <Style.Triggers>
                    <DataTrigger Binding='{Binding DoubleValue}' Value='1'>
                        <Setter Property='FrameworkElement.Width' Value='200'/>
                    </DataTrigger>
                </Style.Triggers>
            </Style>";

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

            Control control = new Control();

            BindingTestDataContext dataContext = new BindingTestDataContext();

            dataContext.DoubleValue = 1;

            control.Style = style;

            Assert.AreEqual(100, control.Width);

            control.DataContext = dataContext;

            Assert.AreEqual(200, control.Width);

            dataContext.DoubleValue = 2;

            Assert.AreEqual(100, control.Width);

            dataContext.DoubleValue = 1;

            Assert.AreEqual(200, control.Width);

            control.DataContext = null;

            Assert.AreEqual(100, control.Width);
        }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 4
0
        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);
        }